 |
 |
GoldenEye 007 Nintendo 64 Community, GoldenEye X, Nintendo 64 Games Discussion GoldenEye Cheats, GoldenEye X Codes, Tips, Help, Nintendo 64 Gaming Community
|
 |
 |
 |
 |
|
 |
 |
 |
 |
 |
zoinkity 007


Joined: 24 Nov 2005 Posts: 1729
 |
Posted: Wed Feb 09, 2011 11:12 am Post subject: GCC and malloc |
 |
|
This has been a persistant problem, and seems specific to gcc.
For whatever reason, malloc isn't memory-safe. Say, for instance, I allocate block a then call a function that may or may not use the pointer, it may just randomly change the data in the allocated block. For instance:
Code: |
#include <stdio>
#include <stdlib>
void thingtodo() {
printf("random line of text that will corrupt allocated memory\n");
}
main() {
int x,
*block=NULL;
block = (int*)calloc(1000);
thingtodo();
for(x=0;x<1000;x++) printf("%i%s",block[x],x%16 ? " ":"\n");
return 0;
}
|
This code will not print 10000 zeroes to my screen! The text in thingtodo() will invariably be set in the allocated memory region. Now, does this make any sense whatsoever?
Has anyone ever seen this, am I just stupid and it really is supposed to behave like this, or what the heck could be going on? _________________ (\_/) Beware
(O.o) ze
(> <) Hoppentruppen! |
|
|
|
|
|
 |
 |
 |
 |
 |
SubDrag Administrator

Joined: 16 Aug 2006 Posts: 6168
 |
Posted: Tue Feb 15, 2011 4:06 am Post subject: |
 |
|
I've mainly seen malloc, but yeah that doesn't seem right...seems like a PC problem or your compiler is off. |
|
|
|
|
|
 |
 |
 |
 |
 |
|
 |
 |
 |
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
 |