Hi Ted, Ted Unangst wrote on Sun, Jan 13, 2019 at 03:22:41AM -0500: > Ingo Schwarze wrote:
>> So, here is some cleanup: >> * garbage collect useless hand-rolled lookup tables >> * merge one-line helper functions into callers >> * garbage collect obfuscating macros >> * fix one format string error (%d used for u_int) >> * garbage collect setlocale(3) and <locale.h> >> * garbage collect several unused constants >> * minus 45 LOC, no functional change >> >> OK? > I think you may be fixing a bug here... Is that an OK? >> Index: locate/fastfind.c >> =================================================================== >> RCS file: /cvs/src/usr.bin/locate/locate/fastfind.c,v >> retrieving revision 1.14 >> diff -u -p -r1.14 fastfind.c >> --- locate/fastfind.c 8 Dec 2017 17:26:42 -0000 1.14 >> +++ locate/fastfind.c 13 Jan 2019 02:07:47 -0000 >> @@ -126,10 +126,8 @@ fastfind_mmap >> u_char bigram1[NBG], bigram2[NBG], path[PATH_MAX]; >> >> #ifdef FF_ICASE >> - /* use a lookup table for case insensitive search */ >> - u_char table[UCHAR_MAX + 1]; >> - >> - tolower_word(pathpart); >> + for (p = pathpart; *p != '\0'; p++) >> + *p = tolower(*p); >> #endif /* FF_ICASE*/ >> >> /* init bigram table */ >> @@ -156,11 +154,8 @@ fastfind_mmap >> p = pathpart; >> patend = patprep(p); >> cc = *patend; >> - >> #ifdef FF_ICASE >> - /* set patend char to true */ >> - table[TOLOWER(*patend)] = 1; >> - table[toupper(*patend)] = 1; >> + cc = tolower(cc); >> #endif /* FF_ICASE */ > I cannot see where that table is zeroed. > It lives on the stack, it could contain anything. Good point. Then again, if that bug stings, it only causes bogus matches in the pre-match phase (and only with -i). The real comparison is done later on the complete strings, see the calls to fnmatch(3) and strstr(3) bwlow. So the bug probably only ruined -i performance, but did not lead to invalid results. Yours, Ingo