summaryrefslogtreecommitdiff
path: root/src/stringmap.c
diff options
context:
space:
mode:
authorfergus.henderson <fergushenderson@users.noreply.github.com>2008-05-09 19:23:50 +0000
committerfergus.henderson <fergushenderson@users.noreply.github.com>2008-05-09 19:23:50 +0000
commitde55241b6f7b87dbf9df203dbeceab8fffb12e75 (patch)
treefb4d2300b49fc995075f28c377e19b12efe21c46 /src/stringmap.c
parenta31b5d6a22150bc54c93166910ba9f351081c659 (diff)
downloaddistcc-git-de55241b6f7b87dbf9df203dbeceab8fffb12e75.tar.gz
Fix what appears to be a bug in the handling of DISTCC_CMDLIST.
The documentation is not very clear, but distccd was documented as matching against the last DISTCC_CMDLIST_NUMWORDS words of the command, where I think by words they meant directory components. For example, if the file refered to by DISTCC_CMDLIST contains the line "/usr/bin/i686-blah-blah/gcc", and DISTCC_CMDLIST_NUMWORDS=2, only commands which end in "/i686-blah-blah/gcc" would be matched. The bug is that a command "i686-blah-blah/gcc" should be considered to match. Likewise, if DISTCC_CMDLIST contains the line "/usr/bin/gcc", and DISTCC_CMDLIST_NUMWORDS is 1 (or not set), then plain "gcc" should be allowed to match. Reviewers: Dan Kegel, Craig Silverstein
Diffstat (limited to 'src/stringmap.c')
-rw-r--r--src/stringmap.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/src/stringmap.c b/src/stringmap.c
index 2c3d26f..ed820ca 100644
--- a/src/stringmap.c
+++ b/src/stringmap.c
@@ -45,8 +45,10 @@ stringmap_t *stringmap_load(const char *filename, int numFinalWordsToMatch)
for (pos=len-1, w=0; pos>0; pos--) {
if (buf[pos] == '/') {
w++;
- if (w >= numFinalWordsToMatch)
+ if (w >= numFinalWordsToMatch) {
+ pos++;
break;
+ }
}
}
@@ -65,8 +67,10 @@ const char *stringmap_lookup(const stringmap_t *map, const char *string)
for (pos=len-1, w=0; pos>0; pos--) {
if (string[pos] == '/') {
w++;
- if (w >= map->numFinalWordsToMatch)
+ if (w >= map->numFinalWordsToMatch) {
+ pos++;
break;
+ }
}
}
for (i=0; i<map->n; i++) {
@@ -96,7 +100,7 @@ void dumpMap(stringmap_t *sm)
assert(c); \
assert(!strcmp(b, c)); } }
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
FILE *fp;
stringmap_t *sm;
@@ -104,13 +108,42 @@ main(int argc, char **argv)
fp = fopen("stringmap_test.dat", "w");
fprintf(fp, "/foo/bar/bletch\n");
fclose(fp);
-
-
sm = stringmap_load("stringmap_test.dat", 1);
dumpMap(sm);
verifyMap(sm, "/bar/bletch", "/foo/bar/bletch");
- verifyMap(sm, "bletch", NULL);
+ verifyMap(sm, "bletch", "/foo/bar/bletch");
+ verifyMap(sm, "/whatever/bletch", "/foo/bar/bletch");
+ verifyMap(sm, "baz", NULL);
verifyMap(sm, "/foo/bar/bletch", "/foo/bar/bletch");
+
+ fp = fopen("stringmap_test.dat", "w");
+ fprintf(fp, "/usr/bin/gcc\n");
+ fprintf(fp, "/usr/bin/cc\n");
+ fclose(fp);
+ sm = stringmap_load("stringmap_test.dat", 1);
+ dumpMap(sm);
+ verifyMap(sm, "/usr/bin/gcc", "/usr/bin/gcc");
+ verifyMap(sm, "/usr/bin/cc", "/usr/bin/cc");
+ verifyMap(sm, "gcc", "/usr/bin/gcc");
+ verifyMap(sm, "cc", "/usr/bin/cc");
+ verifyMap(sm, "g77", NULL);
+
+ fp = fopen("stringmap_test.dat", "w");
+ fprintf(fp, "/usr/bin/i686-blah-blah/gcc\n");
+ fprintf(fp, "/usr/bin/i386-blah-blah/gcc\n");
+ fclose(fp);
+ sm = stringmap_load("stringmap_test.dat", 2);
+ dumpMap(sm);
+ verifyMap(sm, "/usr/bin/i686-blah-blah/gcc",
+ "/usr/bin/i686-blah-blah/gcc");
+ verifyMap(sm, "/usr/bin/i386-blah-blah/gcc",
+ "/usr/bin/i386-blah-blah/gcc");
+ verifyMap(sm, "i686-blah-blah/gcc", "/usr/bin/i686-blah-blah/gcc");
+ verifyMap(sm, "i386-blah-blah/gcc", "/usr/bin/i386-blah-blah/gcc");
+ verifyMap(sm, "gcc", NULL);
+ verifyMap(sm, "g77", NULL);
+
+ return 0;
}
#endif