Hacker News new | ask | show | jobs
by jeffbee 703 days ago
"Attempt to read from address 0x9c" doesn't strike me as "null pointer". It's an invalid address and it doesn't really matter if it was null or not.
5 comments

As an example to illustrate the sibling comments’ explanations:

int *array = NULL

int position = 0x9C

int a = *(array[pos]) //equivalent to *(array + 0x9C) - dereferencing NULL+0x9C, which is just 0x9C

This will segfault (or equivalent) due to reading invalid memory at address 0x9C. Most people would call array[pos] a null pointer dereference casually, even though it’s actually a 0x9C pointer dereference, because there’s very little effective difference between them.

Now, whether this case was actually something like this (dereferencing some element of a null array pointer) or something like type confusion (value 0x9C was supposed to be loaded into an int, or char, or some other non-pointer type) isn’t clear to me. But I haven’t dug into it really, someone smarter than me could probably figure out which it is.

Except we don't see the instructions you'd expect to see if the code was as you describe.

https://x.com/taviso/status/1814762302337654829

What we are witnessing quite starkly in this thread is that the majority of HN commenters are the kinds of people exposed to anti-woke/DEI culture warriors on Twitter.
0x9c (156 dec) is still a very small number, all things considered. To me that sounds like attempting to access an offset from null - for instance, using a null pointer to a struct type, and trying to access one of its member fields.
Could just as easily be accessing an uninitialized pointer, especially given there is a null check immediately before.
It is pretty common for null pointers to structures to have members dereferenced at small offsets, and people usually consider those null dereferences despite not literally being 0. (However, the assembly generated in this case does not match that access pattern, and in fact there was an explicit null check before the dereference.)
Such an invalid access of a very small address probably does result from a nullptr error:

    struct BigObject {
        char stuff[0x9c]; // random fields
        int field;
    }
    BigObject* object = nullptr;
    printf("%d", object->field);
That will result in "Attempt to read from address 0x9c". Just because it's not trying to read from literal address 0x0 doesn't mean it's not nullptr error.
9C means that it's a NULL address plus some offset of 9C. Like a particular field of a struct.