Live data from Hacker News

*(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

youtube.com

81–90 of 199 posts

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#81
post #64
post #28

Earlier quoted context omitted.

On ATmega processors, the register file is mapped to 0, so this would be writing 0 to r0.. which GCC reserves as a dedicated 0 register anyway.

The PDP-10 did that. There was actually core memory at addresses 0-15 but if you had registers they overlaid that. Yes, I said if you had registers--if you were cheap you could buy your PDP-10 without registers and all the instructions that referenced registers would use core instead. Since the registers were in effect just 16 words of fast semiconductor memory overlaying the first 16 words of slow core memory you co…

I seem to recall stories that if you put a small loop there, it could end up uninterruptible, with the CPU hung.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#82

Not a big fan of the format of the talk. The guy is a good orator, but it takes ages to go to the point. A bit annoying if you're actually interested in the technical part rather than the jokes.

If you use GPT-4 with Browsing turned on and supply it with the title, it will find the page and use the transcript and you can ask it questions. Then you can look at the transcripts to find the spots and verify. Alternatively, if you have an AI-enabled browser you can ask it about the transcript once you open it.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#83

Old school comment... back in the day, there were computers on which dereferencing the null pointer would in fact return zero. And given that a typical linked list is terminated by a null, mistakes could creep in where "points to a 0" was checked when "pointer is 0" should have been. Needless to say, code like this would crash in mysterious ways when compiled on a machine where location 0, while readable, had nonzero…

[deleted]

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#84
post #29

Earlier quoted context omitted.

Not quite, I think. Since this is a char pointer being used, only the first byte of the interrupt address would be zeroed. Since in real mode those are far pointers, the lower byte of the segment would be zeroed. So xx00:xxxx. But yes, the interrupt table was my first thought when reading the headline.

Char can be the same size as short or int. You can't assume it is one byte.

You can't assume char is one octet. It is one byte by definition.

A byte is CHAR_BIT bits, where CHAR_BIT >= 8. (It's exactly 8 on most implementations; DSPs are the most common exception).

short and int are both required to be at least 16 bits wide. It's possible for int to be 1 byte (sizeof (int) == 1), but only if CHAR_BIT >= 16.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#85
post #23

Earlier quoted context omitted.

If I'm understanding what you're saying correctly, the memory location with address 0 is actually a writable address, but with the value being used semantically to handle division by zero? It's kind of wild to me that would even something that's even allowed to be done manually, let alone required by a certain mode. Is this something provided for compatibility reasons that you'd have to opt into, or is it just someth…

Back in the day there were no protections. You could write to any address whether it was used by the CPU for interrupt vectors, part of the OS, hardware addresses, anything.

Sure, but I'm asking if that's something that's enabled by default today or not. I don't see why it's unreasonable for things that were useful "back in the day" to not be available with the default arguments on current versions of compilers but available with certain flags. I'm not sure why my question touched a nerve, because I'm genuinely asking both if I understand correctly and if it's something that needs a flag to enable.

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#86

Not a big fan of the format of the talk. The guy is a good orator, but it takes ages to go to the point. A bit annoying if you're actually interested in the technical part rather than the jokes.

If you use GPT-4 with Browsing turned on and supply it with the title, it will find the page and use the transcript and you can ask it questions. Then you can look at the transcripts to find the spots and verify. Alternatively, if you have an AI-enabled browser you can ask it about the transcript once you open it.

I will do prompt injection in the next talk, just for you

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#87
post #80

Earlier quoted context omitted.

I’m glad you appreciated me saying exactly this in the talk

Ah fuck, I grepped the YouTube transcript for WASM/WebAssembly but I guess youtube's automatic captions aren't very good. I feel silly now for not watching the video before commenting.

This is the way ;)

Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]

#89
post #41

Old school comment... back in the day, there were computers on which dereferencing the null pointer would in fact return zero. And given that a typical linked list is terminated by a null, mistakes could creep in where "points to a 0" was checked when "pointer is 0" should have been. Needless to say, code like this would crash in mysterious ways when compiled on a machine where location 0, while readable, had nonzero…

IBM AIX is a Unix-like system on which dereferencing a null pointer for a read is guaranteed to return zero. But writes will crash. It’s pretty weird.

HP-UX binaries also had an attribute that would control this behavior.

https://docstore.mik.ua/manuals/hp-ux/en/B2355-60130/chatr_p...

Wonderful fun when they shipped a Kerberos library that unconditionally dereferenced a potentially null optional pointer-to-struct, relying on the executable to be set in the “null tolerant” mode!

Post reply on HN