/*drl added 01/23/2001 Gives you the number of characters in an
expanded escape squences. This can be different from strlen bc/ of
escaped nulls. */
-int cstring_lengthExpandEscapes (cstring p_s);
+extern size_t cstring_lengthExpandEscapes (cstring p_s);
extern bool cstring_containsLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ;
extern ctype ctype_getBaseType (ctype p_c) /*@*/ ;
extern ctype ctype_makeArray (ctype p_c);
-extern ctype ctype_makeFixedArray (ctype p_c, long p_size);
+extern ctype ctype_makeFixedArray (ctype p_c, size_t p_size);
extern ctype ctype_makeInnerArray (ctype p_c);
-extern ctype ctype_makeInnerFixedArray (ctype p_c, long p_size);
+extern ctype ctype_makeInnerFixedArray (ctype p_c, size_t p_size);
extern ctype ctype_makeConj (ctype p_c1, ctype p_c2);
extern ctype ctype_makeParamsFunction (ctype p_base, /*@only@*/ uentryList p_p);
extern ctype ctype_widest (ctype, ctype) /*@*/ ;
/* drl modified */
-extern long int ctype_getArraySize (ctype p_c);
+extern size_t ctype_getArraySize (ctype p_c);
/*end drl add functions */
/* Should only be used in uentry.c */
/*drl7x 11/28/00*/
-extern bool sRef_isFixedArray (sRef p_s) /*@*/;
-
-extern long int sRef_getArraySize (sRef p_s) /*@*/;
+extern bool sRef_isFixedArray (sRef p_s) /*@*/;
+extern size_t sRef_getArraySize (sRef p_s) /*@*/;
extern /*@observer@*/ cstring sRef_ntMessage (sRef p_s);
extern void sRef_resetLen (sRef p_s) /*@modifies p_s@*/ ;
{
if (sRef_isFixedArray(el))
{
- long int size;
+ size_t size;
DPRINTF((message("%s is a fixed array",
sRef_unparse(el))));
size = sRef_getArraySize(el);
{
FLG_ENUMINT, FLG_MACROMATCHNAME,
FLG_STRINGLITNOROOM,
+ FLG_STRINGLITNOROOMFINALNULL,
FLG_MACROUNDEF, FLG_RELAXQUALS,
FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
FLG_CHECKSTRICTGLOBALIAS,
FLG_SHIFTIMPLEMENTATION,
FLG_BUFFEROVERFLOWHIGH,
FLG_BUFFEROVERFLOW,
- FLG_LITERALOVERSIZE,
INVALID_FLAG
} ;
FLG_CHARINTLITERAL,
FLG_ZEROBOOL,
FLG_BUFFEROVERFLOWHIGH,
- FLG_LITERALOVERSIZE,
+ FLG_STRINGLITNOROOM,
+ FLG_STRINGLITNOROOMFINALNULL,
INVALID_FLAG
} ;
FLG_EVALORDER, FLG_USEDEF,
FLG_NESTEDEXTERN,
- FLG_LITERALOVERSIZE, FLG_LITERALUNDERSIZE,
-
/* warn use flags */
FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
FLG_BUFFEROVERFLOWHIGH,
FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
- FLG_LITERALOVERSIZE, FLG_LITERALUNDERSIZE,
-
/* memtrans flags */
FLG_EXPOSETRANS,
FLG_OBSERVERTRANS,
}
/*@i3534 @*/
-/*@ignore@*/
+/*@ignore@*/ /* !!! DRL don't ignore large segments like this without a good reason! */
/* changes strings like "sdf" "sdfsd" into "sdfsdfsd"*/
/* This function understands that "sdf\" \"sdfsdf" is okay*/
return ret;
}
-static mstring doExpandEscapes (cstring s, /*@out@*/ int * len)
+static mstring doExpandEscapes (cstring s, /*@out@*/ size_t *len)
{
char *ptr;
mstring ret;
char * retPtr;
-
llassert(cstring_isDefined (s));
/*this function is like sctring_expandEscapses */
mstring cstring_expandEscapes (cstring s)
{
- int len;
+ size_t len;
mstring ret;
-
ret = doExpandEscapes (s, &len);
return ret;
}
-int cstring_lengthExpandEscapes (cstring s)
+size_t cstring_lengthExpandEscapes (cstring s)
{
- int len;
-
+ size_t len;
mstring tmpStr, tmpStr2;
tmpStr = doMergeString (s);
tmpStr2 = doExpandEscapes (tmpStr, &len);
-
cstring_free(tmpStr);
cstring_free(tmpStr2);
return len;
}
-
-
cstring cstring_replaceChar(/*@returned@*/ cstring c, char oldChar, char newChar)
{
char *ptr;
return c;
}
-
/*@end@*/
static ctype cttable_addDerived (ctkind p_ctk, /*@keep@*/ ctbase p_cnew, ctype p_base);
static ctype cttable_addFull (/*@keep@*/ ctentry p_cnew);
static bool ctentry_isInteresting (ctentry p_c) /*@*/;
-static /*@notnull@*/ /*@only@*/ ctbase ctbase_makeFixedArray (ctype p_b, long p_size) /*@*/ ;
+static /*@notnull@*/ /*@only@*/ ctbase ctbase_makeFixedArray (ctype p_b, size_t p_size) /*@*/ ;
/*
** These are file-static macros (used in ctype.c). No way to
typedef struct
{
ctype base;
- long size;
+ size_t size;
} *tfixed;
typedef union
case 'F':
{
ctype ct = ctype_undump (c);
- int size;
+ size_t size;
reader_checkChar (c, '/');
- size = reader_getInt (c);
+ size = size_fromInt (reader_getInt (c));
reader_checkChar (c, '|');
return (ctbase_makeFixedArray (ct, size));
}
}
static /*@notnull@*/ /*@only@*/ ctbase
-ctbase_makeFixedArray (ctype b, long size)
+ctbase_makeFixedArray (ctype b, size_t size)
{
ctbase c = ctbase_new ();
called by ctype_getArraySize
*/
-long int ctbase_getArraySize (ctbase ctb)
+size_t ctbase_getArraySize (ctbase ctb)
{
- /*drl 1/25/2002 fixed discover by Jim Francis */
+ /*drl 1/25/2002 fixed discovered by Jim Francis */
ctbase r;
-
llassert (ctbase_isDefined (ctb) );
r = ctbase_realType (ctb);
llassert (ctbase_isFixedArray(r) );
-
-
return (r->contents.farray->size);
-
}
}
}
-ctype ctype_makeFixedArray (ctype c, long size)
+ctype ctype_makeFixedArray (ctype c, size_t size)
{
ctype res;
res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
return res;
}
-ctype ctype_makeInnerFixedArray (ctype c, long size)
+ctype ctype_makeInnerFixedArray (ctype c, size_t size)
{
ctype res;
if (ctype_isFixedArray (c))
{
ctype cb = ctype_baseArrayPtr (c);
- long osize = ctype_getArraySize (c);
-
- res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size),
- osize);
+ size_t osize = ctype_getArraySize (c);
+
+ res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
}
else if (ctype_isArray (c))
{
if (ctype_isFixedArray (c))
{
ctype cb = ctype_baseArrayPtr (c);
- long osize = ctype_getArraySize (c);
-
- res = ctype_makeFixedArray (ctype_makeInnerArray (cb),
- osize);
+ size_t osize = ctype_getArraySize (c);
+
+ res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
}
else
{
/* requires that the type is an fixed array */
/* return the size of the array */
-long int ctype_getArraySize (ctype c)
+size_t ctype_getArraySize (ctype c)
{
- long int size;
+ size_t size;
ctbase ctb;
/*@observer@*/ lltok exprData_getOpTok (exprData data) /*@*/
{
- llassertretval (data != exprData_undefined, exprNode_undefined);
+ llassert (data != exprData_undefined);
return (data->op->op);
}
return ret;
}
-
static void exprNode_checkStringLiteralLength (ctype t1, exprNode e2)
{
multiVal mval = exprNode_getValue (e2);
cstring slit;
- int len;
+ size_t len;
if (ctype_isFixedArray (t1))
{
- int nelements = long_toInt (ctype_getArraySize (t1));
+ size_t nelements = ctype_getArraySize (t1);
llassert (multiVal_isString (mval));
slit = multiVal_forceString (mval);
if (ctype_isFixedArray (t1))
{
- int nelements = long_toInt (ctype_getArraySize (t1));
+ size_t nelements = ctype_getArraySize (t1);
DPRINTF (("Checked array: %s / %d",
ctype_unparse (t1), nelements));
}
else
{
- if (exprNodeList_size (vals) != nelements)
+ if (exprNodeList_size (vals) != size_toInt (nelements))
{
hasError = optgenerror
- (exprNodeList_size (vals) > nelements ? FLG_INITSIZE : FLG_INITALLELEMENTS,
+ (exprNodeList_size (vals) > size_toInt (nelements)
+ ? FLG_INITSIZE : FLG_INITALLELEMENTS,
message ("Initializer block for "
"%s has %d element%&, but declared as %s: %q",
exprNode_unparse (el),
{
sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
}
-# if 0
+
if (exprNode_isStringLiteral (e)
&& (ctype_isArray (ct))
&& (ctype_isChar (ctype_realType (ctype_baseArrayPtr (ct)))))
** If t is a char [], the literal is copied.
*/
- cstring slit;
+ exprNode_checkStringLiteralLength (ct, e);
+ sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
+ ret->val = multiVal_copy (e->val);
+ sRef_setNullTerminatedState (ret->sref);
+
if (multiVal_isDefined (e->val))
{
- slit = multiVal_forceString (e->val);
- }
- else
- {
- slit = cstring_undefined;
+ cstring slit = multiVal_forceString (e->val);
+ sRef_setLen (ret->sref, cstring_length (slit) + 1);
}
- sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
- ret->val = multiVal_copy (e->val);
-
- if (cstring_isDefined (slit))
+ if (ctype_isFixedArray (ct))
{
- if (ctype_isFixedArray (ct))
- {
- long int alength = ctype_getArraySize (ct);
-
- if (alength < cstring_length (slit) + 1)
- {
- voptgenerror
- (FLG_LITERALOVERSIZE,
- ("Array initialized to string literal bigger than allocated size (literal is %d chars long (plus one for nul terminator), array size is %d): %s",
- cstring_length (slit),
- alength,
- exprNode_unparse (e)),
- e->loc);
- }
- else if (alength > cstring_length (slit))
- {
- voptgenerror
- (FLG_LITERALUNDERSIZE,
- ("Array initialized to string literal smaller than allocated size (literal is %d chars long (plus one for nul terminator), array size is %d), could waste storage: %s",
- cstring_length (slit),
- alength,
- exprNode_unparse (e)),
- e->loc);
- }
- else
- {
- ;
- }
- }
- else
- {
- sRef_setNullTerminatedState (ret->sref);
- sRef_setSize (ret->sref, cstring_length (slit) + 1);
- sRef_setLen (ret->sref, cstring_length (slit) + 1);
- }
+ sRef_setSize (ret->sref, size_toInt (ctype_getArraySize (ct)));
}
}
else
-# endif
{
doAssign (ret, e, TRUE);
}
int maxlen = context_getLineLen () - 3;
cstring st = cstring_undefined;
fileId lastFile = fileId_invalid;
+ bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT);
if (filelocList_isDefined (s))
{
st = message ("%q, ", st);
}
- st = message ("%q%d,%d",
- st, fileloc_lineno (s->elements[i]),
- fileloc_column (s->elements[i]));
+ if (parenFormat)
+ {
+ st = message ("%q(%d,%d)",
+ st, fileloc_lineno (s->elements[i]),
+ fileloc_column (s->elements[i]));
+ }
+ else
+ {
+ st = message ("%q%d:%d",
+ st, fileloc_lineno (s->elements[i]),
+ fileloc_column (s->elements[i]));
+ }
+
linelen += 3 + int_log (fileloc_lineno (s->elements[i]))
+ int_log (fileloc_column (s->elements[i]));
}
"memory bounds checking (sets boundsread and boundswrite)",
"Memory read or write may be out of bounds of allocated storage.", 0, 0
},
- {
- FK_BOUNDS, FK_MEMORY, modeFlag,
- "literaloversize",
- FLG_LITERALOVERSIZE,
- "string literal is too large for allocated array",
- "String literal is too large for allocated array.", 0, 0
- },
- {
- FK_BOUNDS, FK_MEMORY, modeFlag,
- "literalundersize",
- FLG_LITERALUNDERSIZE,
- "string literal is smaller than allocated array (space may be wasted)",
- "More storage is allocated for a string literal than the length of the literal. "
- "If the array is not set later, this is a waste of storage.",
- 0, 0
- },
{
FK_BOUNDS, FK_MEMORY, plainFlag,
"boundsread",
qtype qtype_addQual (qtype qt, qual q)
{
+ DPRINTF (("Add qual: %s / %s", qtype_unparse (qt), qual_unparse (q)));
+
if (qtype_isDefined (qt))
{
qt->quals = qualList_add (qt->quals, q);
}
+ DPRINTF (("==> %s", qtype_unparse (qt)));
return qt;
}
return ( ctype_isFixedArray (c) );
}
-long int sRef_getArraySize (sRef p_s) /*@*/ {
+size_t sRef_getArraySize (sRef p_s) /*@*/
+{
ctype c;
llassert (sRef_isFixedArray(p_s) );
DPRINTF (( message ("sRef_getArraySize getting array size for %s", sRef_unparse(p_s) ) ));
c = sRef_getType (p_s);
-
- return (ctype_getArraySize (c) );
+ return (ctype_getArraySize (c));
}
void sRef_setValue (sRef s, multiVal val)
else if (qual_isUnused (qel))
{
uentry_setUsed (ue, fileloc_undefined);
+ DPRINTF (("Used: %s", uentry_unparseFull (ue)));
}
else if (qual_isExternal (qel))
{
{
fileloc loc = setLocation ();
uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
-
+
uentry_reflectQualifiers (ue, idDecl_getQuals (t));
if (!uentry_isExtern (ue))
usymtab_entries (copy, ue)
{
- if (uentry_isValid (ue))
+ if (uentry_isValid (ue) && !uentry_isGlobalMarker (ue))
{
filelocList uses = uentry_getUses (ue);
int size = filelocList_realSize (uses);
UNITTESTS = \
help \
abstptr abstract alias alttypes ansireserved argorder \
- args arraydims arrayinit blocks break cases cast charlit clauses commentchar compdestroy \
+ args arraydims arrayinit arraylit blocks break cases cast charlit clauses commentchar compdestroy \
compoundliterals compoundstmt constannot controldepth csyntax czechnames czechoslovaknames deadparam \
decl divzero enum exports external fields flags forbody format freearray \
funcpointer functionmacro glob globals impabstract info init inparam internal iter keep libs \
arrayinit:
-$(SPLINTR) arrayinit.c -expect 9
+.PHONY: arraylit
+arraylit:
+ -$(SPLINTR) arraylit.c -expect 2
+ -$(SPLINTR) arraylit.c +stringliteralsmaller -expect 4
+
.PHONY: blocks
blocks:
-$(SPLINTR) blocks.c -expect 4
staticarray:
-$(SPLINTR) staticarray.c -expect 3
+###
+### evans 2002-03-16: Default setting of stringliteralnoroomfinalnull changed
+###
+
.PHONY: stringliteral
stringliteral:
- -$(SPLINTR) stringliteral.c +stringliteralnoroomfinalnull -expect 4
- -$(SPLINTR) stringliteral.c -expect 3
+ -$(SPLINTR) stringliteral.c -stringliteralnoroomfinalnull -expect 3
+ -$(SPLINTR) stringliteral.c -expect 4
.PHONY: strings
strings:
./argorder5.c \
./args.c \
./arrayinit.c \
+ ./arraylit.c \
./blocks.c \
./branchstate.c \
./break.c \
argorder.expect \
args.expect \
arrayinit.expect \
+ arraylit.expect \
blocks.expect \
branchstate.expect \
break.expect \
UNITTESTS = \
help \
abstptr abstract alias alttypes ansireserved argorder \
- args arraydims arrayinit blocks break cases cast charlit clauses commentchar compdestroy \
+ args arraydims arrayinit arraylit blocks break cases cast charlit clauses commentchar compdestroy \
compoundliterals compoundstmt constannot controldepth csyntax czechnames czechoslovaknames deadparam \
decl divzero enum exports external fields flags forbody format freearray \
funcpointer functionmacro glob globals impabstract info init inparam internal iter keep libs \
./argorder5.c \
./args.c \
./arrayinit.c \
+ ./arraylit.c \
./blocks.c \
./branchstate.c \
./break.c \
argorder.expect \
args.expect \
arrayinit.expect \
+ arraylit.expect \
blocks.expect \
branchstate.expect \
break.expect \
arrayinit:
-$(SPLINTR) arrayinit.c -expect 9
+.PHONY: arraylit
+arraylit:
+ -$(SPLINTR) arraylit.c -expect 2
+ -$(SPLINTR) arraylit.c +stringliteralsmaller -expect 4
+
.PHONY: blocks
blocks:
-$(SPLINTR) blocks.c -expect 4
staticarray:
-$(SPLINTR) staticarray.c -expect 3
+###
+### evans 2002-03-16: Default setting of stringliteralnoroomfinalnull changed
+###
+
.PHONY: stringliteral
stringliteral:
- -$(SPLINTR) stringliteral.c +stringliteralnoroomfinalnull -expect 4
- -$(SPLINTR) stringliteral.c -expect 3
+ -$(SPLINTR) stringliteral.c -stringliteralnoroomfinalnull -expect 3
+ -$(SPLINTR) stringliteral.c -expect 4
.PHONY: strings
strings:
--- /dev/null
+# include <stdio.h>
+
+int main (/*@unused@*/ int argc, /*@unused@*/ char **argv) /*@*/
+{
+ /*@observer@*/ char *unmodstr = "unmodifiable string";
+ /*@exposed@*/ char modstr[20] = "modifiable string";
+ /*@unused@*/ char modstr1[5] = "12345"; /* not enough space */
+ /*@unused@*/ char modstr2[6] = "12345";
+ /*@unused@*/ char modstr3[7] = "12345"; /* if +stringliteralsmaller */
+
+ modstr1 = modstr;
+
+ unmodstr[0] = 'U'; /* line 6; not OK */
+ modstr[0] = 'M'; /* line 7; OK */
+
+ fprintf (stderr, "mod: %s mod1: %s", modstr, modstr1);
+ return 0;
+}
--- /dev/null
+
+arraylit.c: (in function main)
+arraylit.c:7:34: String literal with 6 characters is assigned to char [5] (no
+ room for null terminator): "12345"
+arraylit.c:13:3: Suspect modification of observer unmodstr[0]:
+ unmodstr[0] = 'U'
+
+Finished checking --- 2 code warnings, as expected
+
+arraylit.c: (in function main)
+arraylit.c:6:38: String literal with 18 characters is assigned to char [20]
+ (possible waste of storage): "modifiable string"
+arraylit.c:7:34: String literal with 6 characters is assigned to char [5] (no
+ room for null terminator): "12345"
+arraylit.c:9:34: String literal with 6 characters is assigned to char [7]
+ (possible waste of storage): "12345"
+arraylit.c:13:3: Suspect modification of observer unmodstr[0]:
+ unmodstr[0] = 'U'
+
+Finished checking --- 4 code warnings, as expected
-stringliteral.c:2:15: String literal with 9 characters is assigned to char [8]
- (no room for final null terminator): "\000\000\000\000\000\000\000\000"
stringliteral.c:3:16: String literal with 9 characters is assigned to char [8]
(no room for null terminator): "\000\000\000\000\000\000\000\001"
stringliteral.c:4:16: String literal with 5 characters is assigned to char [4]
terminator) is assigned to char [4] (insufficient storage available):
"abcdef"
-Finished checking --- 4 code warnings, as expected
+Finished checking --- 3 code warnings, as expected
+stringliteral.c:2:15: String literal with 9 characters is assigned to char [8]
+ (no room for final null terminator): "\000\000\000\000\000\000\000\000"
stringliteral.c:3:16: String literal with 9 characters is assigned to char [8]
(no room for null terminator): "\000\000\000\000\000\000\000\001"
stringliteral.c:4:16: String literal with 5 characters is assigned to char [4]
terminator) is assigned to char [4] (insufficient storage available):
"abcdef"
-Finished checking --- 3 code warnings, as expected
+Finished checking --- 4 code warnings, as expected