On 1. 6. 25 22:06, Daniel Sahlberg wrote:
Hi,
When checking Brane's work on the CMake build system, I investigated a few
compiler warnings. There are a few instances of "‘avail’ may be used
uninitialized", Avail is passed to select_value (as the parameter *len) and
SHOULD be initialized there, however there is a default:-statement in a
switch that is "Not reachable" according to a comment and this path leaves
*len uninitialised.
That's in serf_headers_read(), right? Well, the compiler is wrong,
because select_value() just returned from the case (ctx->state ==
READ_DONE), so avail is definitely initialized to NULL, and its value
used in serf_headers_read() only if (ctx->state == READ_DONE). I prefer
to leave such warnings alone, because silencing them only papers over a
compiler limitation.
By the way, I don't see this warning from clang, neither at -O0 nor at
-O3. Which compiler is this? gcc?
Can we do something to silence this warning? The below seems to work, but
maybe there are better ways
[[[
Index: serf_trunk/buckets/headers_buckets.c
===================================================================
--- serf_trunk/buckets/headers_buckets.c (revision 1926051)
+++ serf_trunk/buckets/headers_buckets.c (working copy)
@@ -312,6 +312,7 @@ static void select_value(
return;
default:
/* Not reachable */
+ *len = 0;
return;
}
]]]
If this silences the warning, that just proves that the compiler didn't
bother to do a full data flow analysis. Heh, according to one of the
older versions of the C standard (IIRC ISO C90 and maybe C11 as well), a
standard-compliant compiler was not actually required to produce any
runnable code, and was allowed to produce any diagnostic message it
liked. So , essentially, this used to be a valid, ISO standard compliant
C compiler:
#include <stdio.h>
int main (void)
{
fprintf(stderr, "warning: your program may contain errors\n");
return 0;
}
I think they may have fixed that slight omission :)
-- Brane