[splint-discuss] incomplete deallocation
Greg White
pcguy11 at live.com
Thu Nov 13 17:30:14 PST 2008
> From: Michael.Wojcik at microfocus.com
>>> static const nk_hdr nk_hdr0 = {0};
>>> ...
>>> n = malloc(sizeof *n);
>>> *n = nk_hdr0;
>>
>> OK I made the changes you suggested but splint is now giving me the
>> following message:
>> Initializer block for nk_hdr0 has 1 field, but nk_hdr has 5 fields: 0
>> Initializer does not set every field in the structure. (Use -
>> fullinitblock to inhibit warning)
>>
>> Code:
>> static const nk_hdr nk_hdr0 = {0};
>> nk_hdr *n = NULL;
>>
>> n = (nk_hdr*) malloc(sizeof(*n));
>> if (n == NULL) {
>> printf("can't allocate memory for n\n");
>> return -1;
>> }
>> *n = nk_hdr0;
>>
>> Did I do something wrong?
>
> No. This is a misfeature in Splint. Compound initializers with fewer
> fields than the aggregate type being initialized are well-defined by the
> ISO C standard, and the "{0}" initializer in particular is a
> widely-recognized idiom. (Splint should really silently ignore any
> "short" initializer that ends with a 0 constant.)
>
> This sort of false-positive message is a common problem with lint-style
> static analyzers, which is why they introduced source code annotations.
>
> The proper way to fix it is with an annotation. This should do it:
>
> /*@ -fullinitblock @*/
> static const nk_hdr nk_hdr0 = {0};
> /*@ +fullinitblock @*/
>
> or alternatively:
>
> static const nk_hdr nk_hdr0 = /*@i1@*/ {0};
>
> (The "i1" annotation means "ignore exactly one item from here to the end
> of this line".)
>
> You can also just remove the "= {0}" part, since static variables are
> implicitly initialized to {0} if no explicit initializer is present.
I just removed the = {0} and everything is fine now.
Thanks for the help,
_________________________________________________________________
Get 5 GB of storage with Windows Live Hotmail.
http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_5gb_112008
More information about the splint-discuss
mailing list