Re: /bzr/squid3/trunk/ r11692: Cleanup: make IP address show AnyAddr() as v4 or v6

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Wed, 31 Aug 2011 18:02:35 +1200

On 31/08/11 10:55, Alex Rousskov wrote:
> On 08/30/2011 09:51 AM, Amos Jeffries wrote:
>
>> + if (IsIPv6())
>> + memcpy(buf,"::\0", min(static_cast<unsigned int>(3),blen));
>> + else if (IsIPv4())
>> + memcpy(buf,"0.0.0.0\0", min(static_cast<unsigned int>(8),blen));
>
> There should be no reason to put a second 0-terminator into a
> "guaranteed to be 0-terminated" string constant.

That one is there to ensure the destination ends up nul-terminated when
blen is larger without having to dicker around with 4 extra lines of
code calculating the amount copied and assigning the final byte
separately and without the xstrncpy additional padding being written.

We seem not to be allowed to memcpy(dst, "::", 3) for some reason
despite as you say, the termination guarantee.

Amos

-- 
Please be using
   Current Stable Squid 2.7.STABLE9 or 3.1.15
   Beta testers wanted for 3.2.0.10
Received on Wed Aug 31 2011 - 06:02:42 MDT

This archive was generated by hypermail 2.2.0 : Wed Aug 31 2011 - 12:00:03 MDT