Always initialize c_options=NULL - #2751
Conversation
|
Thanks for raising this. Could the problem be not the Do we need a specific version of clang to replicate this? |
|
This fails to compile for me: // reprex.c
#include <stddef.h>
extern void consume_pointer(void* ptr);
extern int is_null(void* arg);
void test_pagerank_options(void* options, int algo) {
void* c_options; // Declared without initialization
if (!is_null(options)) {
if (algo == 1) {
c_options = options;
} else {
c_options = NULL;
}
}
// When is_null(options) is true, c_options is read uninitialized here:
consume_pointer(c_options);
}clang -Wsometimes-uninitialized -c reprex.coutput: clang --version
# Ubuntu clang version 14.0.0-1ubuntu1.1
# Target: x86_64-pc-linux-gnu
# Thread model: posix
# InstalledDir: /usr/bin |
|
It does have the feel of a false positive to it, since it doesn't cause any "real" issues, but there is still UB here as summarized by Gemini:
|
|
Of course, thanks for the simple example. Will adapt the code generator. |
|
Thanks, included in #2792. |
This was flagged by
clang's-Wsometimes-uninitialized.