From: Ivan Maidanski Date: Sat, 9 Nov 2013 07:37:09 +0000 (+0400) Subject: Eliminate GCC warning about uninitialized 'hhdr' in GC_allochblk_nth X-Git-Tag: gc7_4_0~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bab0f6b5b84919a4a676591c4b61267bdd7d1cb6;p=gc Eliminate GCC warning about uninitialized 'hhdr' in GC_allochblk_nth * allchblk.c (GC_allochblk_nth): Replace "for" condition with conditional "return" since otherwise GCC reports "'hhdr' may be used uninitialized" warning in case of -O0 optimization level; remove comment about bogus compiler warning; refine comment for "thishdr" local variable. --- diff --git a/allchblk.c b/allchblk.c index 25e11a46..98085b6d 100644 --- a/allchblk.c +++ b/allchblk.c @@ -640,20 +640,18 @@ STATIC struct hblk * GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split) { struct hblk *hbp; - hdr * hhdr; /* Header corr. to hbp */ - /* Initialized after loop if hbp !=0 */ - /* Gcc uninitialized use warning is bogus. */ + hdr * hhdr; /* Header corr. to hbp */ struct hblk *thishbp; - hdr * thishdr; /* Header corr. to hbp */ + hdr * thishdr; /* Header corr. to thishbp */ signed_word size_needed; /* number of bytes in requested objects */ signed_word size_avail; /* bytes available in this block */ size_needed = HBLKSIZE * OBJ_SZ_TO_BLOCKS(sz); /* search for a big enough block in free list */ - hbp = GC_hblkfreelist[n]; - for(; 0 != hbp; hbp = hhdr -> hb_next) { - GET_HDR(hbp, hhdr); + for (hbp = GC_hblkfreelist[n];; hbp = hhdr -> hb_next) { + if (NULL == hbp) return NULL; + GET_HDR(hbp, hhdr); /* set hhdr value */ size_avail = hhdr->hb_sz; if (size_avail < size_needed) continue; if (size_avail != size_needed) {