Elimiate one of the umphteen directory variables in doLookupId()
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 18 Sep 2012 03:56:46 +0000 (06:56 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 18 Sep 2012 03:56:46 +0000 (06:56 +0300)
- Use dynamically allocated cdnbuf in the non-absolute path case (when
  exactly that occurs is another question) too instead of the on-stack
  dir[], making the two paths a bit more similar.

lib/fprint.c

index ba21656..08a1b19 100644 (file)
@@ -132,7 +132,6 @@ static int doLookupId(fingerPrintCache cache,
             rpmsid dirNameId, rpmsid baseNameId,
             fingerPrint *fp)
 {
-    char dir[PATH_MAX];
     char * end;                    /* points to the '\0' at the end of "buf" */
     struct stat sb;
     char *buf = NULL;
@@ -160,18 +159,21 @@ static int doLookupId(fingerPrintCache cache,
 
        /* if the current directory doesn't exist, we might fail. 
           oh well. likewise if it's too long.  */
-       dir[0] = '\0';
-       if (realpath(".", dir) != NULL) {
-           end = dir + strlen(dir);
+
+       /* XXX we should let realpath() allocate if it can */
+       cdnbuf = xmalloc(PATH_MAX);
+       cdnbuf[0] = '\0';
+       if (realpath(".", cdnbuf) != NULL) {
+           end = cdnbuf + strlen(cdnbuf);
            if (end[-1] != '/') *end++ = '/';
-           end = stpncpy(end, cleanDirName, sizeof(dir) - (end - dir));
+           end = stpncpy(end, cleanDirName, sizeof(cdnbuf) - (end - cdnbuf));
            *end = '\0';
-           (void)rpmCleanPath(dir); /* XXX possible /../ from concatenation */
-           end = dir + strlen(dir);
+           (void)rpmCleanPath(cdnbuf); /* XXX possible /../ from concatenation */
+           end = cdnbuf + strlen(cdnbuf);
            if (end[-1] != '/') *end++ = '/';
            *end = '\0';
-           cleanDirName = dir;
-           cdnl = end - dir;
+           cleanDirName = cdnbuf;
+           cdnl = end - cdnbuf;
        }
     }