Re: Segfault in HTCP CLR request on 64-bit

From: Henrik Nordstrom <henrik_at_henriknordstrom.net>
Date: Fri, 02 Oct 2009 09:57:45 +0200

fre 2009-10-02 klockan 02:52 -0400 skrev Matt W. Benjamin:
> Bzero? Is it an already-allocated array/byte sequence? (Apologies, I haven't seen the code.) Assignment to NULL/0 is in fact correct for initializing a sole pointer, and using bzero for that certainly isn't typical. Also, for initializing a byte range, memset is preferred [see Linux BZERO(3), which refers to POSIX.1-2008 on that point].
>
> STYLE(9) says use NULL rather than 0, and it is clearer. But C/C++ programmers should know that NULL is 0. And note that at least through 1998, initialization to 0 was the preferred style in C++, IIRC.

You are both right.

the whole stuff should be zeroed before filled in to avoid accidental
leakage of "random" values from the stack, which also makes the explicit
assignment redundant.

bzero is not the right call (BSD specific), memset is preferred.

In C (which is what Squid-2 is written in) NULL is the right initializer
for pointers in all contexts.

C++ is different... no universally accepted pointer initializer value
there due to the slightly different type checks on pointers, often
needing casting.

But something is fishy here.. see my comment in bugzilla.

Regards
Henrik
Received on Fri Oct 02 2009 - 07:57:55 MDT

This archive was generated by hypermail 2.2.0 : Fri Oct 02 2009 - 12:00:04 MDT