X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=miscutil.c;h=ab1ccaed3c04c2adeb9a4ad3f3ee9af71f18d918;hp=22776d8ec95191bbc2c8b2afd67bc7e07e07c32c;hb=7d0d27186d473655bc895c40515277d4e6488439;hpb=01a42dd85e9c8debe6a03e532a7335ccb4bdafdf diff --git a/miscutil.c b/miscutil.c index 22776d8e..ab1ccaed 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.52 2007/08/19 12:32:34 fabiankeil Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.53 2007/09/09 18:20:20 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -44,6 +44,10 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.52 2007/08/19 12:32:34 fabianke * * Revisions : * $Log: miscutil.c,v $ + * Revision 1.53 2007/09/09 18:20:20 fabiankeil + * Turn privoxy_strlcpy() into a function and try to work with + * b0rked snprintf() implementations too. Reported by icmp30. + * * Revision 1.52 2007/08/19 12:32:34 fabiankeil * Fix a conversion warning. * @@ -1132,16 +1136,18 @@ long int pick_from_range(long int range) *********************************************************************/ size_t privoxy_strlcpy(char *destination, const char *source, const size_t size) { - snprintf(destination, size, "%s", source); - /* - * Platforms that lack strlcpy() also tend to have - * a broken snprintf implementation that doesn't - * guarantee nul termination. - * - * XXX: the configure script should detect and reject those. - */ - destination[(size > 1) ? size-1 : 0] = '\0'; - + if (0 < size) + { + snprintf(destination, size, "%s", source); + /* + * Platforms that lack strlcpy() also tend to have + * a broken snprintf implementation that doesn't + * guarantee nul termination. + * + * XXX: the configure script should detect and reject those. + */ + destination[size-1] = '\0'; + } return strlen(source); } #endif /* def USE_PRIVOXY_STRLCPY */