]> git.ozlabs.org Git - ccan/commitdiff
generator: Don't print variable unless the generator returned a value
authorJon Griffiths <jon_p_griffiths@yahoo.com>
Mon, 22 Aug 2016 14:39:38 +0000 (02:39 +1200)
committerJon Griffiths <jon_p_griffiths@yahoo.com>
Mon, 29 Aug 2016 04:54:58 +0000 (16:54 +1200)
clang warns that the generator assignment is conditional which could
lead to passing an undefined variable to printf.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
ccan/generator/test/compile_fail-4.c

index f7297cffcd34f11ad5d3cf652ad8b52b5e228abe..712180265a62e9ea5ec5492a974a4d187f3e006f 100644 (file)
@@ -16,8 +16,8 @@ int main(int argc, char *argv[])
        int val;
 #endif
 
        int val;
 #endif
 
-       generator_next_val(val, g);
-       printf("%d", val);
+       if (generator_next_val(val, g))
+               printf("%d", val);
 
        exit(0);
 }
 
        exit(0);
 }