]> granicus.if.org Git - graphviz/commitdiff
pathcanon: avoid reusing `dots` variable for unrelated values
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 4 Aug 2021 03:10:07 +0000 (20:10 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 8 Aug 2021 17:41:15 +0000 (10:41 -0700)
This branch reuses the `dots` variable, previously used for counting the number
of periods in the path, for storing the result of symlink resolution. This is
unnecessary (`dots` is immediately overwritten with the value 4 after this), and
is getting in the way of cleaning up some compiler warnings in this area.

lib/ast/pathcanon.c

index aad084e3bf682a5d6f99670914da6e54b590d630..9231adf802d93d2143ebd627c10ddda3627163c3 100644 (file)
@@ -134,20 +134,20 @@ char *pathcanon(char *path, int flags)
 
                    c = *(t - 1);
                    *(t - 1) = 0;
-                   dots = pathgetlink(phys, buf, sizeof(buf));
+                   int len = pathgetlink(phys, buf, sizeof(buf));
                    *(t - 1) = c;
-                   if (dots > 0) {
-                       if ((t + dots + 1) >= e) { /* make sure path fits in buf */
+                   if (len > 0) {
+                       if ((t + len + 1) >= e) { /* make sure path fits in buf */
                            strcpy(path, s);
                             return 0;
                        }
                        loop++;
-                       strcpy(buf + dots, s - (*s != 0));
+                       strcpy(buf + len, s - (*s != 0));
                        if (*buf == '/')
                            p = r = path;
                        v = s = t = p;
                        strcpy(p, buf);
-                   } else if (dots < 0 && errno == ENOENT) {
+                   } else if (len < 0 && errno == ENOENT) {
                        if (flags & PATH_EXISTS) {
                            strcpy(path, s);
                            return 0;