]> andersk Git - splint.git/blobdiff - src/cstring.c
Cleaned up code in doMergeString
[splint.git] / src / cstring.c
index 043519896172dbd9e39b474d2b2574af9c7b51c3..90d0c17b20d2d965e9b8293570cb40591e62308b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -265,7 +265,7 @@ void cstring_stripChars (cstring s, const char *clist)
 
       for (i = 0; i < size_toInt (size); i++)
        {
-         /*drl bee: is*/       
+               
          char c = s[i];
          
          if (strchr (clist, c) != NULL)
@@ -277,10 +277,10 @@ void cstring_stripChars (cstring s, const char *clist)
              
              for (j = i; j < size_toInt (size); j++)
                {
-                 /*drl bee: is*/ /*drl bee: is*/ s[j] = s[j+1];
+                 s[j] = s[j+1];
                }
              
-             /*drl bee: is*/ s[size] = '\0'; 
+             s[size] = '\0'; 
              i--;
            }
        }
@@ -375,8 +375,7 @@ cmpcode cstring_genericEqual (cstring s, cstring t,
          t++;
        }
 
-  /*drl bee: ib*/
-      /*drl bee: ib*/ 
+        
       if (*s == '\0' && *t != '\0')
        {
          return CGE_DISTINCT;
@@ -592,7 +591,7 @@ cstring_clip (cstring s, size_t len)
   else
     {
       llassert (s != NULL);
-      /*drl bee: mrms*/ 
+      
       *(s + len) = '\0';
     }
   
@@ -611,7 +610,7 @@ cstring_elide (cstring s, size_t len)
       cstring sc = cstring_create (len);
       
       strncpy (sc, s, len);
-      /*drl bee: mrms*/ 
+      
       *(sc + len - 1) = '\0';
       *(sc + len - 2) = '.';      
       *(sc + len - 3) = '.';      
@@ -633,8 +632,7 @@ cstring_fill (cstring s, size_t n) /*@requires n >= 0 @*/
     {
       for (i = 0; i < n; i++)
        {
-       /*drl bee: is*/
-         /*drl bee: is*/ 
+                 
          *t++ = *s++;
        }
       *t = '\0';
@@ -643,13 +641,12 @@ cstring_fill (cstring s, size_t n) /*@requires n >= 0 @*/
     {
       for (i = 0; i < len; i++)
        {
-       /*drl bee: is*/
-/*drl bee: is*/ 
+       
          *t++ = *s++;
        }
       for (i = 0; i < n - len; i++)
        {
-/*drl bee: is*/ 
+
          *t++ = ' ';
        }
       *t = '\0';
@@ -667,7 +664,7 @@ cstring_downcase (cstring s)
       cstring ot = t;
       char c;
       
/*drl bee: lhnt*/      while ((c = *s) != '\0')
+      while ((c = *s) != '\0')
        {
          if (c >= 'A' && c <= 'Z')
            {
@@ -676,7 +673,7 @@ cstring_downcase (cstring s)
          *t++ = c;
          s++;
        }
-     /*drl bee: is*/  *t = '\0';
+      *t = '\0';
       
       return ot;
     }
@@ -698,13 +695,13 @@ cstring_appendChar (/*@only@*/ cstring s1, char c)
     {  
       strcpy (s, s1);
       *(s + l) = c;
-      /*drl bee: dm*/ *(s + l + 1) = '\0';
+      *(s + l + 1) = '\0';
       sfree (s1); 
     }
   else
     {
       *(s) = c;
-      /*drl bee: dm*/  *(s + 1) = '\0';
+       *(s + 1) = '\0';
     } 
 
   return s;
@@ -727,7 +724,6 @@ cstring_concatFree1 (cstring s, cstring t)
   return res;
 }
 
-# ifndef NOLCL
 /*@only@*/ cstring 
 cstring_concatChars (cstring s, char *t)
 {
@@ -735,7 +731,6 @@ cstring_concatChars (cstring s, char *t)
   cstring_free (s);
   return res;
 }
-# endif
 
 /*@only@*/ cstring 
 cstring_concatLength (cstring s1, char *s2, size_t len) /*@requires maxSet(s2) >= (len - 1) @*/
@@ -755,7 +750,7 @@ cstring_concat (cstring s, cstring t) /*@requires maxSet(s) >= 0 @*/
 
   if (cstring_isDefined (s))
     {
-    /*drl bee: sl*/   strcpy (ret, s);
+      strcpy (ret, s);
     }
   if (cstring_isDefined (t))
     {
@@ -780,7 +775,7 @@ cstring_prependChar (char c, /*@temp@*/ cstring s1)
   size_t l = cstring_length (s1);
   char *s = (char *) dmalloc (sizeof (*s) * (l + 2));
   
-/*drl bee: dm*/   *(s) = c;
+  *(s) = c;
 
   if (cstring_isDefined (s1)) 
     {
@@ -789,11 +784,10 @@ cstring_prependChar (char c, /*@temp@*/ cstring s1)
       /*@=mayaliasunique@*/ 
     }
 
/*drl bee: dm*/ *(s + l + 1) = '\0';
+ *(s + l + 1) = '\0';
   return s;
 }
 
-# ifndef NOLCL
 bool
 cstring_hasNonAlphaNumBar (cstring s)
 {
@@ -801,7 +795,7 @@ cstring_hasNonAlphaNumBar (cstring s)
 
   if (cstring_isUndefined (s)) return FALSE;
 
-/*drl bee: lhnt*/  while ((c = (int) *s) != (int) '\0')
+ while ((c = (int) *s) != (int) '\0')
     {
       if ((isalnum (c) == 0) && (c != (int) '_')
          && (c != (int) '.') && (c != (int) CONNECTCHAR))
@@ -813,14 +807,13 @@ cstring_hasNonAlphaNumBar (cstring s)
     }
   return FALSE;
 }
-# endif
 
 /*@only@*/ /*@notnull@*/ cstring 
 cstring_create (size_t n)
 {
   char *s = dmalloc (sizeof (*s) * (n + 1));
   
-  /*drl bee: dm*/ *s = '\0';
+  *s = '\0';
   return s;
 }
 
@@ -832,11 +825,10 @@ cstring_copySegment (cstring s, size_t findex, size_t tindex)
   llassert (cstring_isDefined (s));
   llassert (cstring_length (s) > tindex);
 
-  strncpy (res, (s + findex), size_fromInt ((tindex - findex + 1)));
+  strncpy (res, (s + findex), size_fromInt (size_toInt (tindex - findex) + 1));
   return res;
 }
 
-# ifndef NOLCL
 lsymbol cstring_toSymbol (cstring s)
 {
   lsymbol res = lsymbol_fromString (s);
@@ -844,7 +836,6 @@ lsymbol cstring_toSymbol (cstring s)
   cstring_free (s);
   return res;
 }
-# endif
 
 cstring cstring_bsearch (cstring key, char **table, int nentries)
 {
@@ -886,7 +877,7 @@ cstring cstring_bsearch (cstring key, char **table, int nentries)
       if (mid != 0 && mid < nentries - 1)
        {
          llassert (cstring_compare (key, table[mid - 1]) > 0);
-       /*drl bee: ndv*/  llassert (cstring_compare (key, table[mid + 1]) < 0);
+        llassert (cstring_compare (key, table[mid + 1]) < 0);
        }
 
       return res;
@@ -900,7 +891,7 @@ extern /*@observer@*/ cstring cstring_advanceWhiteSpace (cstring s)
   if (cstring_isDefined (s)) {
     char *t = s;
 
/*drl bee: lhnt*/   while (*t != '\0' && isspace ((int) *t)) {
+   while (*t != '\0' && isspace ((int) *t)) {
       t++;
     }
 
@@ -910,9 +901,6 @@ extern /*@observer@*/ cstring cstring_advanceWhiteSpace (cstring s)
   return cstring_undefined;
 }
 
-/*@i3534 @*/
-/*@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*/
 static mstring doMergeString (cstring s)
@@ -965,7 +953,8 @@ static mstring doMergeString (cstring s)
              retPtr++;
              *retPtr = '\0';
              BADEXIT;
-             return ret;
+
+             /*@notreached@*/ return ret;
            }
          else
            {
@@ -981,7 +970,7 @@ static mstring doMergeString (cstring s)
       ptr++;
       
     }/* end while */
-  retPtr = '\0';
+  *retPtr = '\0';
   return ret;
 }
 
@@ -1123,7 +1112,8 @@ static mstring doExpandEscapes (cstring s, /*@out@*/ size_t *len)
   /* add the null character */
   *retPtr = '\0';
 
-  *len = retPtr - ret;
+  llassert(  (retPtr-ret) >= 0 );
+  *len = (size_t)(retPtr - ret);
   return ret;
 }
 
@@ -1172,7 +1162,7 @@ cstring cstring_replaceChar(/*@returned@*/ cstring c, char oldChar, char newChar
 
   return c;
 }
-/*@end@*/
+
 
 
 
This page took 0.089348 seconds and 4 git commands to generate.