From 1f5800673bd95a9f912262134d651a319ab6224b Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 21 Aug 2014 12:34:26 +0400 Subject: [PATCH] cmd/gc: fix undefined behavior UndefinedBehaviorSanitizer claims it is UB in C: src/cmd/gc/racewalk.c:422:37: runtime error: member access within null pointer of type 'Node' (aka 'struct Node') src/cmd/gc/racewalk.c:423:37: runtime error: member access within null pointer of type 'Node' (aka 'struct Node') LGTM=rsc R=dave, rsc CC=golang-codereviews https://golang.org/cl/125570043 --- src/cmd/gc/racewalk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cmd/gc/racewalk.c b/src/cmd/gc/racewalk.c index 285bd78a258..27581702ccb 100644 --- a/src/cmd/gc/racewalk.c +++ b/src/cmd/gc/racewalk.c @@ -419,8 +419,10 @@ racewalknode(Node **np, NodeList **init, int wr, int skip) ret: if(n->op != OBLOCK) // OBLOCK is handled above in a special way. racewalklist(n->list, init); - racewalknode(&n->ntest, &n->ntest->ninit, 0, 0); - racewalknode(&n->nincr, &n->nincr->ninit, 0, 0); + if(n->ntest != N) + racewalknode(&n->ntest, &n->ntest->ninit, 0, 0); + if(n->nincr != N) + racewalknode(&n->nincr, &n->nincr->ninit, 0, 0); racewalklist(n->nbody, nil); racewalklist(n->nelse, nil); racewalklist(n->rlist, nil);