X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=src%2Fmiscutil.c;h=77489135bd63e1740997ac72c3f32303d43d6968;hb=1a61b31c7bcc7470c79519507440fd47a8a8cc01;hp=53b3b4d76fce6b5688597f0fc828a257a7f45ddb;hpb=2da19eb8eff90f6c9a7cb46ff891643e89d50a55;p=privoxy.git diff --git a/src/miscutil.c b/src/miscutil.c index 53b3b4d7..77489135 100644 --- a/src/miscutil.c +++ b/src/miscutil.c @@ -1,7 +1,7 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.37 2002/04/26 18:29:43 jongfoster Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 2.3 2002/09/25 13:00:41 oes Exp $"; /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ + * File : $Source: /cvsroot/ijbswa//current/src/miscutil.c,v $ * * Purpose : zalloc, hash_string, safe_strerror, strcmpic, * strncmpic, chomp, and MinGW32 strdup @@ -36,6 +36,19 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.37 2002/04/26 18:29:43 jongfost * * Revisions : * $Log: miscutil.c,v $ + * Revision 2.3 2002/09/25 13:00:41 oes + * Made strcmpic and strncmpic safe against NULL arguments + * (which are now treated as empty strings). + * + * Revision 2.2 2002/08/26 11:16:33 sarantis + * Fix typo. + * + * Revision 2.1 2002/06/04 17:22:37 jongfoster + * Adding comments + * + * Revision 2.0 2002/06/04 14:34:21 jongfoster + * Moving source files to src/ + * * Revision 1.37 2002/04/26 18:29:43 jongfoster * Fixing this Visual C++ warning: * miscutil.c(710) : warning C4090: '=' : different 'const' qualifiers @@ -296,7 +309,7 @@ void write_pid_file(void) * to "switch" a string the one of my favorites. * * Parameters : - * 1 : s : string to be hashed. + * 1 : s = string to be hashed. * * Returns : an unsigned long variable with the hashed value. * @@ -399,6 +412,9 @@ char *safe_strerror(int err) *********************************************************************/ int strcmpic(const char *s1, const char *s2) { + if (!s1) s1 = ""; + if (!s2) s2 = ""; + while (*s1 && *s2) { if ( ( *s1 != *s2 ) && ( ijb_tolower(*s1) != ijb_tolower(*s2) ) ) @@ -429,7 +445,9 @@ int strcmpic(const char *s1, const char *s2) int strncmpic(const char *s1, const char *s2, size_t n) { if (n <= 0) return(0); - + if (!s1) s1 = ""; + if (!s2) s2 = ""; + while (*s1 && *s2) { if ( ( *s1 != *s2 ) && ( ijb_tolower(*s1) != ijb_tolower(*s2) ) ) @@ -454,7 +472,7 @@ int strncmpic(const char *s1, const char *s2, size_t n) * from a string. * * Parameters : - * 1 : s : string to be chomped. + * 1 : string = string to be chomped. * * Returns : chomped string * @@ -812,25 +830,28 @@ int simplematch(char *pattern, char *text) if ((*pat == *txt) || ((*pat == ']') && (charmap[*txt / 8] & (1 << (*txt % 8)))) ) { - /* Sucess, go ahead */ + /* + * Sucess: Go ahead + */ pat++; } - else + else if (!wildcard) { - /* In wildcard mode, just try again after failiure */ - if(wildcard) - { - pat = fallback; - } - - /* Else, bad luck */ - else - { - return 1; - } + /* + * No match && no wildcard: No luck + */ + return 1; + } + else if (pat != fallback) + { + /* + * Wildcard mode && nonmatch beyond fallback: Rewind pattern + */ + pat = fallback; + continue; } txt++; - } + } /* Cut off extra '*'s */ if(*pat == '*') pat++; @@ -852,7 +873,7 @@ int simplematch(char *pattern, char *text) * 1 : string = string to be duplicated * 2 : len = number of bytes to duplicate * - * Returns : pointer to copy, or NULL if failiure + * Returns : pointer to copy, or NULL if failure * *********************************************************************/ char *bindup(const char *string, size_t len) @@ -884,8 +905,8 @@ char *bindup(const char *string, size_t len) * the filename. * * Parameters : - * 1 : dir: Name of directory or NULL for none. - * 2 : file: Name of file. Should not be NULL or empty. + * 1 : dir = Name of directory or NULL for none. + * 2 : file = Name of file. Should not be NULL or empty. * * Returns : "dir/file" (Or on windows, "dir\file"). * It allocates the string on the heap. Caller frees.