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

Reply via email to