Comment

Comment by sqrt_1

Related to unspecified vs undefined. I recall some C code was trying to be tricky and read from just allocated memory. Something like:

int* ptr = malloc(size); if(ptr[offset] == 0) { }

The code was assuming that the value in an allocated buffer did not change.

However, it was pointed out in review that it could change with these steps:

1) The malloc allocates from a new memory page. This page is often not mapped to a physical page until written to.

2) The reads just return the default (often 0 value) as the page is not mapped.

3) Another allocation is made that is written to the same page. This maps the page to physical memory which then changes the value of the original allocation.

parent sqrt_1 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton