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)

comment:1 by Daniel Marjamäki, 9 years ago

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.

in reply to:  1 comment:2 by Daniel Marjamäki, 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 amai, 9 years ago

IMHO not within that translation unit. Quite sure somewhere else in the codebase...

comment:4 by kidkat, 4 years ago

I cannot reproduce this with any released version since 1.43.

comment:5 by chrchr, 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:6 by kidkat, 4 years ago

It requires --language=c - I was testing with a .cpp file.

comment:7 by kidkat, 19 months ago

Keywords: c added
Note: See TracTickets for help on using tickets.