Re: [dwm] malloc'ed client in manage()

From: Szabolcs Nagy <nszabolcs_AT_gmail.com>
Date: Sun, 7 Sep 2008 16:13:01 +0200

On 9/7/08, Brendan MacDonell <macdonellba_AT_gmail.com> wrote:
> On Sun, Sep 7, 2008 at 5:25 AM, Szabolcs Nagy <nszabolcs_AT_gmail.com> wrote:
>> is it because of null pointer might not be represented as zeros?
>>
>> the point is good, but i doubt X would run on such platform ;)
>
> Unfortunately, the patch uses structure assignment from an unmodified
> static variable, so everything just gets set to 0 anyway.

not true:
"
If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static
storage duration is not initialized explicitly, then:
 -- if it has pointer type, it is initialized to a null pointer;
 -- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
 -- if it is an aggregate, every member is initialized (recursively)
according to these rules;
 -- if it is a union, the first named member is initialized
(recursively) according to these rules.
"
so pointers will become null pointer not all-bits-zero

a cleaner c99 solution:
c = malloc(..); // +checks..
*c = (Client){}; // initialize correctly
Received on Sun Sep 07 2008 - 14:13:01 UTC

This archive was generated by hypermail 2.2.0 : Sun Sep 07 2008 - 14:24:04 UTC