]> andersk Git - splint.git/blobdiff - src/exprNode.c
Fixed bug reproted by Jim Francis. Bug was triggered by running splint on typedef...
[splint.git] / src / exprNode.c
index 9796fdfad7b0792afe10166a77b251631187ae21..fbccd3410ff157da05351b7815416238bd7ab7fd 100644 (file)
@@ -17,8 +17,8 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on splint: splint@cs.virginia.edu
-** To report a bug: splint-bug@cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
 ** For more information: http://www.splint.org
 */
 /*
@@ -1057,30 +1057,53 @@ static void exprNode_checkStringLiteralLength (ctype t1, exprNode e2)
 
   if (ctype_isFixedArray (t1))
     {
+
       int nelements = long_toInt (ctype_getArraySize (t1));
       
       llassert (multiVal_isString (mval));
       slit = multiVal_forceString (mval);
-      len = cstring_length (slit);
+      
+      len = cstring_lengthExpandEscapes (slit);
+      
       
       if (len == nelements)
        {
+         mstring temp;
+
+         temp = cstring_expandEscapes(slit);
+
+         if (temp[len-1] == '\0')
+           {
+             voptgenerror 
+               (FLG_STRINGLITNOROOMFINALNULL,
+                message ("String literal with %d character%& "
+                         "is assigned to %s (no room for final null terminator): %s",
+                         len + 1,
+                         ctype_unparse (t1),
+                         exprNode_unparse (e2)),
+                e2->loc);
+           }
+         else
+           {
+         
+         
          voptgenerror 
            (FLG_STRINGLITNOROOM,
             message ("String literal with %d character%& "
                      "is assigned to %s (no room for null terminator): %s",
-                     cstring_length (slit),
+                     len + 1,
                      ctype_unparse (t1),
                      exprNode_unparse (e2)),
-            e2->loc);                        
+            e2->loc);
+           }
        }
       else if (len > nelements) 
        {
          voptgenerror 
            (FLG_STRINGLITTOOLONG,
-            message ("Stirng literal with %d character%& (counting null terminator) "
+            message ("String literal with %d character%& (counting null terminator) "
                      "is assigned to %s (insufficient storage available): %s",
-                     cstring_length (slit),
+                     len + 1,
                      ctype_unparse (t1),
                      exprNode_unparse (e2)),
             e2->loc);                        
@@ -1090,7 +1113,7 @@ static void exprNode_checkStringLiteralLength (ctype t1, exprNode e2)
          voptgenerror 
            (FLG_STRINGLITSMALLER,
             message ("String literal with %d character%& is assigned to %s (possible waste of storage): %s",
-                     cstring_length (slit),
+                     len + 1,
                      ctype_unparse (t1),
                      exprNode_unparse (e2)),
             e2->loc);    
@@ -8095,7 +8118,7 @@ static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
   if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
     {
       exprNodeList vals = exprData_getArgs (val->edata);
-
+      
       DPRINTF (("Check one init: %s", exprNodeList_unparse (vals)));
       DPRINTF (("Type: %s", ctype_unparse (t1)));
 
@@ -8108,6 +8131,9 @@ static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
            {
              int nelements = long_toInt (ctype_getArraySize (t1));
              
+             DPRINTF (("Checked array: %s / %d",
+                       ctype_unparse (t1), nelements));
+
              if (exprNode_isStringLiteral (val))
                {
                  exprNode_checkStringLiteralLength (t1, val);
This page took 0.079709 seconds and 4 git commands to generate.