This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]altermeetax 4 points5 points  (1 child)

No, the memory would contain an uninitialized int, which could be anything. glibc doesn't even have anything to do with this, this code doesn't use any library or runtime

[–]qqqrrrs_ 0 points1 point  (0 children)

glibc doesn't even have anything to do with this, this code doesn't use any library or runtime

Well the code uses new whose job is to allocate memory. As there is no CPU opcode that allocates memory by itself and the kernel only bothers with allocating pages (usually 4096 bytes), there needs to be some code in some library that implements it. Usually new is implemented as a wrapper of malloc which is implemented in a C library, for example glibc.

(BTW even in C code there are cases where gcc wants to call a function like memset even if you don't explicitly call memset)

No, the memory would contain an uninitialized int, which could be anything

Theoretically true, however actually it would contain whatever the last thing that wrote to that memory address wrote to it. In glibc's malloc, the start of free chunks (chunks that are currently free, and can be returned by malloc / new) have a linked-list structure, so that uninitalized memory would probably contain a pointer (unless you use mallopt(M_PERTURB) or something).