I think I have to revisit Kernighan and Ritchie ;-)
Thank you
Markus
"Henrik Nordstrom" <henrik_at_henriknordstrom.net> wrote in message
news:1247481804.11584.13.camel_at_localhost.localdomain...
> Hi Markus
>
> i just saw this change which copies the user string a temporary buffer
> only to \0 terminate it before printf
>
> http://www.squid-cache.org/Versions/v3/3.0/changesets/b9061.patch
>
> While entirely fine it's a little more complex than it need to be.
>
> Instead of copying the unterminated string you can apply a size limit to
> the output. Size limit for %s is in the precision field and causes at
> most that many characters to be copied to the output. When combined with
> the * size specifier one can easily print sized strings without the need
> for \0 termination.
>
> printf("%.*s\n", token.length, token.data);
>
> Regards
> Henrik
>
>
Received on Mon Jul 13 2009 - 22:02:35 MDT
This archive was generated by hypermail 2.2.0 : Tue Jul 14 2009 - 12:00:05 MDT