[splint-discuss] array initialization in structure

Harris, Jeffrey A jeffrey.a.harris at lmco.com
Wed Apr 18 20:41:25 PDT 2012


I'm trying to understand the splint message that we are receiving in some legacy code.  The code compiles successfully without any warnings.

Code:
#define string_parse_type(field,value) char field[sizeof(value)]

struct strStruct
{
    string_parse_type(s1,"string1");
    string_parse_type(s2,"str2");
} mystrs = {
    "string1",
    "str2"
};

Splint warning:
test.c:8:5: String literal with 8 characters (counting null terminator)
   is assigned to char [0] (insufficient storage available): "string1"
   A string literal is assigned to a char array too small to hold it. (Use
   -stringliteraltoolong to inhibit warning)
test.c:9:5: String literal with 5 characters (counting null terminator)
   is assigned to char [0] (insufficient storage available): "str2"
Finished checking

Why does splint think the char arrays have a dimension of 0?  How can I make splint happy with this code?

Thanks,
Jeff Harris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.cs.virginia.edu/pipermail/splint-discuss/attachments/20120419/45139dcd/attachment-0001.html 


More information about the splint-discuss mailing list