Opened 9 years ago
Last modified 19 months ago
#8048 new defect
Missing type declaration in C triggers uninitvar
| Reported by: | amai | Owned by: | noone |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | False positive | Version: | |
| Keywords: | uninitvar c | Cc: |
Description
cppcheck reports a [a.c:9]: (error) Uninitialized variable: dcname for the following incomplete(!) C code (inspired by Samba):
#if 0 #define FSTRING_LEN 256 typedef char fstring[FSTRING_LEN]; #endif void get_dc_name_via_netlogon(fstring dcname); void get_dcs() { fstring dcname; get_dc_name_via_netlogon(dcname); }
It is not shown for the complete/valid version of the code and not if using C++ mode.
Is this the intended behaviour?
Change History (7)
follow-up: 2 comment:1 by , 9 years ago
comment:2 by , 9 years ago
Replying to danielmarjamaki:
Is this the intended behaviour?
I believe I wrote a ticket about such code about half a year ago.
I had the idea to look at how all "fstring" variables are used in the code. if there is
dcname[..]anywhere then the checker could bailout.
oh I have implemented that already. No warning is written for this code:
void get_dc_name_via_netlogon(fstring dcname);
void get_dcs() {
fstring dcname;
get_dc_name_via_netlogon(dcname);
dcname[0]=0;
}
would it be possible somehow to see in the real Samba code that fstring is some array? without seeing the typedef?
comment:3 by , 9 years ago
IMHO not within that translation unit. Quite sure somewhere else in the codebase...
comment:5 by , 4 years ago
Still reproduces with head:
cppcheck.exe --enable=all --inconclusive .\foo.c
Checking foo.c ...
foo.c:4:29: error: Uninitialized variable: dcname [uninitvar]
get_dc_name_via_netlogon(dcname);
^
comment:7 by , 19 months ago
| Keywords: | c added |
|---|
This started with 1.58 and has been bisected to https://github.com/danmar/cppcheck/commit/cf84c211ed775c244b7f0b95f7779e0cf149a853.
I believe I wrote a ticket about such code about half a year ago.
I had the idea to look at how all "fstring" variables are used in the code. if there is
dcname[..]anywhere then the checker could bailout.