Strange memory allocation bug
Posted: Thu Jul 03, 2025 3:58 pm
Hello all!
I am experiencing a strange bug when using the liballoc implementation of malloc.
When first accessing allocated memory, the next write to memory seems to be ignored completely, leaving the memory uninitialised. I have added some example screenshots below:
By moving the declaration of `buf` before assigning to *n:
Edit: forgot to upload the github link https://github.com/Toriiiiiiiiii/Solkern
I am experiencing a strange bug when using the liballoc implementation of malloc.
When first accessing allocated memory, the next write to memory seems to be ignored completely, leaving the memory uninitialised. I have added some example screenshots below:
Code: Select all
int *n = malloc(sizeof(int));
*n = 10;
char buf[10] = {0};
utos(*n, 10, buf);
fputs(1, buf);
fputs(1, "\n");
*n = 12;
utos(*n, 10, buf);
fputs(1, buf);
Code: Select all
int *n = malloc(sizeof(int));
char buf[10] = {0};
*n = 10;
utos(*n, 10, buf);
fputs(1, buf);
fputs(1, "\n");
*n = 12;
utos(*n, 10, buf);
fputs(1, buf);