diff options
author | Wayne Davison <wayned@samba.org> | 2006-01-13 21:40:26 +0000 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2006-01-13 21:40:26 +0000 |
commit | 754302080786fe46c3ce431b6f96b796043e4f62 (patch) | |
tree | 87f513a6866f36b426da51f0c185d57fcf57383b /wildtest.c | |
parent | 47b50b9bd0ec9e9d1704eeab202f4f86623ca955 (diff) | |
download | rsync-754302080786fe46c3ce431b6f96b796043e4f62.tar.gz rsync-754302080786fe46c3ce431b6f96b796043e4f62.tar.bz2 rsync-754302080786fe46c3ce431b6f96b796043e4f62.zip |
Fixed a bug in the explode_mode code that was causing a crash
on BSD systems.
Diffstat (limited to 'wildtest.c')
-rw-r--r-- | wildtest.c | 26 |
1 files changed, 7 insertions, 19 deletions
@@ -47,37 +47,25 @@ run_test(int line, bool matches, bool same_as_fnmatch, #endif if (explode_mod) { - static char *buf; - char *texts[MAXPATHLEN], *hold; + char buf[MAXPATHLEN*2], *texts[MAXPATHLEN]; int pos = 0, cnt = 0, ndx = 0, len = strlen(text); - if (!buf) { - int j; - if (!(buf = calloc(MAXPATHLEN * 2, 1))) - exit(1); - for (j = (MAXPATHLEN-1) / explode_mod; j >= 0; j--) - texts[j] = buf + j * (explode_mod + 1); - } - if (empty_at_start) - texts[ndx++][0] = '\0'; + texts[ndx++] = ""; /* An empty string must turn into at least one empty array item. */ while (1) { - strncpy(texts[ndx++], text + pos, explode_mod); - if (pos + explode_mod >= len) { - texts[ndx-1][len - pos] = '\0'; + texts[ndx] = buf + ndx * (explode_mod + 1); + strlcpy(texts[ndx++], text + pos, explode_mod + 1); + if (pos + explode_mod >= len) break; - } pos += explode_mod; if (!(++cnt % empties_mod)) - texts[ndx++][0] = '\0'; + texts[ndx++] = ""; } if (empty_at_end) - texts[ndx++][0] = '\0'; - hold = texts[ndx]; + texts[ndx++] = ""; texts[ndx] = NULL; matched = wildmatch_array(pattern, (const char**)texts, 0); - texts[ndx] = hold; } else matched = wildmatch(pattern, text); #ifdef COMPARE_WITH_FNMATCH |