Prevent harmless COVERITY warning message of the BAD_ALLOC_STRLEN checker on relative...
authorNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 14 Sep 2011 03:20:05 +0000 (23:20 -0400)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 14 Sep 2011 03:20:05 +0000 (23:20 -0400)
Changed it because it is indeed more maintainable to walk past the '/' and use that afterwards.

lib-src/etags.c
lib-src/ootags.c

index c1e806f..49002f6 100644 (file)
@@ -6650,18 +6650,19 @@ char *file, *dir;
        do                              /* look at the equal chars until '/' */
                fp--, dp--;
        while (*fp != '/');
+       fp ++; /* Advance past the '/' */
 
        /* Build a sequence of "../" strings for the resulting relative file name. */
        i = 0;
        while ((dp = etags_strchr (dp + 1, '/')) != NULL)
                i += 1;
-       res = xnew (3*i + strlen (fp + 1) + 1, char);
+       res = xnew (3*i + strlen (fp) + 1, char);
        res[0] = '\0';
        while (i-- > 0)
                strcat (res, "../");
 
        /* Add the file name relative to the common root of file and dir. */
-       strcat (res, fp + 1);
+       strcat (res, fp);
        free (afn);
 
        return res;
index f843e86..64260fd 100644 (file)
@@ -5070,18 +5070,19 @@ char *file, *dir;
        do                      /* look at the equal chars until '/' */
                fp--, dp--;
        while (*fp != '/');
+       fp ++; /* Advance past the '/' */
 
        /* Build a sequence of "../" strings for the resulting relative file name. */
        i = 0;
        while ((dp = etags_strchr(dp + 1, '/')) != NULL)
                i += 1;
-       res = xnew(3 * i + strlen(fp + 1) + 1, char);
+       res = xnew(3 * i + strlen(fp) + 1, char);
        res[0] = '\0';
        while (i-- > 0)
                strcat(res, "../");
 
        /* Add the file name relative to the common root of file and dir. */
-       strcat(res, fp + 1);
+       strcat(res, fp);
        free(afn);
 
        return res;