Avoid static buffer and extra copy in docdir checking.
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 23 Jul 2007 07:02:54 +0000 (10:02 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 23 Jul 2007 07:02:54 +0000 (10:02 +0300)
From rpm5.org / Ralf S. Engelschall.
(transplanted from 414d128db0aaea7abbd2040e041c2290802eee53)

build/files.c

index 110bce1..1400250 100644 (file)
@@ -1072,13 +1072,12 @@ static int compareFileListRecs(const void * ap, const void * bp)        /*@*/
 static int isDoc(FileList fl, const char * fileName)   /*@*/
 {
     int x = fl->docDirCount;
-    char docdir[PATH_MAX], *d;
+    size_t k, l;
 
+    k = strlen(fileName);
     while (x--) {
-       d = stpcpy(docdir, fl->docDirs[x]);
-       if (*(d-1) != '/') 
-          d = stpcpy(d, "/");
-       if (strncmp(fileName, docdir, strlen(docdir)) == 0) 
+       l = strlen(fl->docDirs[x]);
+       if (l < k && strncmp(fileName, fl->docDirs[x], l) == 0 && fileName[l] == '/')
            return 1;
     }
     return 0;