]> andersk Git - splint.git/commitdiff
Fixed problem with print format for +showalluses.
authorevans1629 <evans1629>
Sun, 17 Mar 2002 03:41:17 +0000 (03:41 +0000)
committerevans1629 <evans1629>
Sun, 17 Mar 2002 03:41:17 +0000 (03:41 +0000)
21 files changed:
src/Headers/cstring.h
src/Headers/lctype.h
src/Headers/sRef.h
src/constraintGeneration.c
src/context.c
src/cstring.c
src/ctbase.i
src/ctype.c
src/exprData.c
src/exprNode.c
src/filelocList.c
src/flags.def
src/qtype.c
src/sRef.c
src/uentry.c
src/usymtab.c
test/Makefile.am
test/Makefile.in
test/arraylit.c [new file with mode: 0644]
test/arraylit.expect [new file with mode: 0644]
test/stringliteral.expect

index d6d886bb1fcfeaab18e30174db75e7d4f32697bc..154cc9160bd03bb0fd0cb7225763fc42e32ec84a 100644 (file)
@@ -213,7 +213,7 @@ extern /*@notnull@*/ cstring  cstring_expandEscapes (cstring p_s);
 /*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) /*@*/ ;
index a58ebaa1c62815f99403f4122bc8ab7f6ccd0a18..ecf61d0446eb0c1e7912bb49b2e55ea288a8ce76 100644 (file)
@@ -263,9 +263,9 @@ extern ctype ctype_fixArrayPtr (ctype p_c);
 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);
@@ -368,7 +368,7 @@ extern /*@unused@*/ void ctype_printTable (void);
 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 */
index 25eee4d97c897d10262f3c50da8a8696003d0d26..bde8d451d01ef974f790bf5c7fbed877ae6b1d5d 100644 (file)
@@ -661,9 +661,8 @@ extern bool sRef_isNotNullTerminated(/*@sef@*/sRef p_s);
 
 
      /*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@*/ ;
index 8de2712c7b8234a48f42a07a883956290f9a9167..c08063d3ce058c39864a8ee5c57167983410d798 100644 (file)
@@ -455,7 +455,7 @@ static exprNode doWhile (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode tes
     {
       if (sRef_isFixedArray(el))
        {
-         long int size;
+         size_t size;
          DPRINTF((message("%s is a fixed array",
                            sRef_unparse(el))));
          size = sRef_getArraySize(el);
index cae02cfc677a21731bd1ac6b3b9585292018a8fd..4037e4d18941eb55969a55bcc1d00bf3a876e459 100644 (file)
@@ -1035,6 +1035,7 @@ context_setModeAux (cstring s, bool warn)
        {
          FLG_ENUMINT, FLG_MACROMATCHNAME,
          FLG_STRINGLITNOROOM,
+         FLG_STRINGLITNOROOMFINALNULL,
          FLG_MACROUNDEF, FLG_RELAXQUALS, 
          FLG_USEALLGLOBS, FLG_CHECKSTRICTGLOBALS,
          FLG_CHECKSTRICTGLOBALIAS,
@@ -1106,7 +1107,6 @@ context_setModeAux (cstring s, bool warn)
          FLG_SHIFTIMPLEMENTATION,
          FLG_BUFFEROVERFLOWHIGH,
          FLG_BUFFEROVERFLOW,
-         FLG_LITERALOVERSIZE,
          INVALID_FLAG 
        } ;
 
@@ -1135,7 +1135,8 @@ context_setModeAux (cstring s, bool warn)
          FLG_CHARINTLITERAL,
          FLG_ZEROBOOL,
          FLG_BUFFEROVERFLOWHIGH,
-         FLG_LITERALOVERSIZE,
+         FLG_STRINGLITNOROOM,
+         FLG_STRINGLITNOROOMFINALNULL,
          INVALID_FLAG 
          } ;
 
@@ -1185,8 +1186,6 @@ context_setModeAux (cstring s, bool warn)
          FLG_EVALORDER, FLG_USEDEF, 
          FLG_NESTEDEXTERN, 
 
-         FLG_LITERALOVERSIZE, FLG_LITERALUNDERSIZE,
-
          /* warn use flags */
          FLG_MULTITHREADED, FLG_PORTABILITY, FLG_SUPERUSER, FLG_IMPLEMENTATIONOPTIONAL,
          FLG_BUFFEROVERFLOWHIGH,
@@ -1311,8 +1310,6 @@ context_setModeAux (cstring s, bool warn)
 
          FLG_COMPDEF, FLG_COMPMEMPASS, FLG_UNIONDEF,
 
-         FLG_LITERALOVERSIZE, FLG_LITERALUNDERSIZE,
-
          /* memtrans flags */
          FLG_EXPOSETRANS,
          FLG_OBSERVERTRANS,
index 3408eaf2388deee05cc889775f66d9fe396aa37b..043519896172dbd9e39b474d2b2574af9c7b51c3 100644 (file)
@@ -911,7 +911,7 @@ extern /*@observer@*/ cstring cstring_advanceWhiteSpace (cstring s)
 }
 
 /*@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*/
@@ -985,12 +985,11 @@ static mstring doMergeString (cstring s)
   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));
   
@@ -1132,23 +1131,20 @@ static mstring doExpandEscapes (cstring s, /*@out@*/ int * len)
 /*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);
@@ -1156,8 +1152,6 @@ int  cstring_lengthExpandEscapes (cstring s)
   return len;
 }
 
-
-
 cstring cstring_replaceChar(/*@returned@*/ cstring c, char oldChar, char newChar)
 {
   char *ptr;
@@ -1178,7 +1172,6 @@ cstring cstring_replaceChar(/*@returned@*/ cstring c, char oldChar, char newChar
 
   return c;
 }
-
 /*@end@*/
 
 
index 03aeabb0fd1f7d1c10f0deacb9c773139a5830b8..2d9c42f6661be2423bab4df0bfbab0d1c63fdef2 100644 (file)
@@ -69,7 +69,7 @@ static void cttable_grow (void);
 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
@@ -168,7 +168,7 @@ typedef struct
 typedef struct
 {
   ctype base;
-  long size;
+  size_t size;
 } *tfixed;
  
 typedef union 
@@ -828,10 +828,10 @@ static ctbase ctbase_undump (d_char *c) /*@requires maxRead(*c) >= 2 @*/
     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));
       }
@@ -1668,7 +1668,7 @@ ctbase_makeArray (ctype b)
 }
 
 static /*@notnull@*/ /*@only@*/ ctbase
-ctbase_makeFixedArray (ctype b, long size)
+ctbase_makeFixedArray (ctype b, size_t size)
 {
   ctbase c = ctbase_new ();
 
@@ -2513,18 +2513,14 @@ ctbase_almostEqual (ctbase c1, ctbase c2)
   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);
-
 }
index 6a309aca62cb8c131e0b41133bd005cc4ccf0f94..6a3bcd663dad4bb4036e7101cf13181398278984 100644 (file)
@@ -315,24 +315,23 @@ ctype_makePointer (ctype c)
     }
 }
 
-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))
     {
@@ -358,10 +357,9 @@ ctype ctype_makeInnerArray (ctype 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
     {
@@ -2742,9 +2740,9 @@ bool ctype_isFixedArray (ctype c)
 /* 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;
 
index 13e2fc8a43530bc873da60840d049a30dbd49a66..b16be355337d7dbd7eaa19f72ed3c9027bbd32c1 100644 (file)
@@ -301,7 +301,7 @@ void exprData_free (/*@only@*/ exprData data, exprKind kind)
 
 /*@observer@*/ lltok exprData_getOpTok (exprData data) /*@*/
 {
-  llassertretval (data != exprData_undefined, exprNode_undefined);
+  llassert (data != exprData_undefined);
   return (data->op->op);
 }
 
index dc2104f6bd94bf04117cf78d49e849ca7eaf895e..8940676c3ebe97021473eeb1262b7a5b6e6a9fb7 100644 (file)
@@ -1049,16 +1049,15 @@ exprNode_fromIdentifier (/*@observer@*/ uentry c)
   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);
@@ -8207,7 +8206,7 @@ static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
 
          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));
@@ -8218,10 +8217,11 @@ static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
                }
              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),
@@ -8584,7 +8584,7 @@ exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
        {
          sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
        }
-# if 0
+
       if (exprNode_isStringLiteral (e)
          && (ctype_isArray (ct))
          && (ctype_isChar (ctype_realType (ctype_baseArrayPtr (ct)))))
@@ -8593,61 +8593,24 @@ exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
          ** 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);
        }
index b011a01094f6c2f25684bfb68704fa1de76475be..cb4454b6aa7e73df73a3a179226c034756e043b5 100644 (file)
@@ -219,6 +219,7 @@ cstring filelocList_unparseUses (filelocList s)
   int maxlen = context_getLineLen () - 3;
   cstring st = cstring_undefined;
   fileId lastFile = fileId_invalid;
+  bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); 
 
   if (filelocList_isDefined (s))
     {
@@ -249,9 +250,19 @@ cstring filelocList_unparseUses (filelocList 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]));
                    }
index c52720b9bf4922d42d502bd9f292879b072f0088..921167eddbd88486a1df4d08d2a17722d02cd7d1 100644 (file)
@@ -1852,22 +1852,6 @@ static flaglist flags =
     "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",
index 5a4a20be653099fe592668388dfee3bd5e032656..42559366bbc8e696aeaf34cce81ff9dd0efc67e5 100644 (file)
@@ -56,11 +56,14 @@ qtype qtype_unknown ()
 
 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;
 }
 
index 030e5c223e1e6ba85d7f824632dba86899c863e9..a1913fa8c1282311fc4a0b2a4b4626585e2bd646 100644 (file)
@@ -10100,14 +10100,14 @@ bool sRef_isFixedArray (sRef p_s) /*@*/ {
   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)
index 787341666e4aff0fa785adf0cd6dd22885c0c494..a7a45a5aa21841089e58c14946dfaec5e6b36316 100644 (file)
@@ -2502,6 +2502,7 @@ uentry_reflectQualifiers (uentry ue, qualList q)
       else if (qual_isUnused (qel))
        {
          uentry_setUsed (ue, fileloc_undefined);         
+         DPRINTF (("Used: %s", uentry_unparseFull (ue)));
        }
       else if (qual_isExternal (qel))
        {
@@ -3087,7 +3088,7 @@ uentry_isSpecialFunction (uentry ue)
     {
       fileloc loc = setLocation ();
       uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
-      
+
       uentry_reflectQualifiers (ue, idDecl_getQuals (t));
 
       if (!uentry_isExtern (ue))
index 14f0a9457145f517ba2e040cdeae82ac9cb00e86..69e810c8fae651f73c6a11676bd82db6b3e85083 100644 (file)
@@ -5583,7 +5583,7 @@ usymtab_displayAllUses ()
 
   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);
index 8b82f51d8178d36bcaa388439bf8c3c6fd501f19..6b149f5ef81ca6b76b9360bf7b5162f9f3630417 100644 (file)
@@ -37,7 +37,7 @@ SPLINTRNEST   = $(SPLINTRNNEST) -exportlocal +debugfcnconstraint
 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 \
@@ -226,6 +226,11 @@ arraydims:
 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
@@ -752,10 +757,14 @@ stack:
 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:
@@ -1017,6 +1026,7 @@ EXTRA_DIST =  ./abst_t.lcl ./abst_t.lcs  \
               ./argorder5.c \
               ./args.c \
               ./arrayinit.c \
+              ./arraylit.c \
               ./blocks.c \
               ./branchstate.c \
               ./break.c \
@@ -1335,6 +1345,7 @@ EXTRA_DIST =  ./abst_t.lcl ./abst_t.lcs  \
               argorder.expect \
               args.expect \
               arrayinit.expect \
+              arraylit.expect \
               blocks.expect \
               branchstate.expect \
               break.expect \
index ac1b25d2484f350522cf96ad0a80045f69c7a88a..b94538bdccc352cf2505cbd6336b176f0bee5a9e 100644 (file)
@@ -114,7 +114,7 @@ SPLINTRNEST = $(SPLINTRNNEST) -exportlocal +debugfcnconstraint
 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 \
@@ -272,6 +272,7 @@ EXTRA_DIST = ./abst_t.lcl ./abst_t.lcs  \
               ./argorder5.c \
               ./args.c \
               ./arrayinit.c \
+              ./arraylit.c \
               ./blocks.c \
               ./branchstate.c \
               ./break.c \
@@ -590,6 +591,7 @@ EXTRA_DIST = ./abst_t.lcl ./abst_t.lcs  \
               argorder.expect \
               args.expect \
               arrayinit.expect \
+              arraylit.expect \
               blocks.expect \
               branchstate.expect \
               break.expect \
@@ -1045,6 +1047,11 @@ arraydims:
 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
@@ -1568,10 +1575,14 @@ stack:
 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:
diff --git a/test/arraylit.c b/test/arraylit.c
new file mode 100644 (file)
index 0000000..3d8afe8
--- /dev/null
@@ -0,0 +1,18 @@
+# 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;
+}
diff --git a/test/arraylit.expect b/test/arraylit.expect
new file mode 100644 (file)
index 0000000..4dc7e25
--- /dev/null
@@ -0,0 +1,20 @@
+
+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
index 729b1284b96ac2400ee0b94551ffb3a0579e470f..a7d072a5e63fa83708df2538419b6635fa4e8485 100644 (file)
@@ -1,6 +1,4 @@
 
-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]
@@ -9,8 +7,10 @@ stringliteral.c:7:16: String literal with 7 characters (counting null
     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]
@@ -19,4 +19,4 @@ stringliteral.c:7:16: String literal with 7 characters (counting null
     terminator) is assigned to char [4] (insufficient storage available):
     "abcdef"
 
-Finished checking --- 3 code warnings, as expected
+Finished checking --- 4 code warnings, as expected
This page took 0.112883 seconds and 5 git commands to generate.