ShootersForever.com Forum Index

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


GCC and malloc

 
Post new topic   Reply to topic    ShootersForever.com Forum Index -> Computer SOS
View previous topic :: View next topic  
zoinkity
007
007


Joined: 24 Nov 2005
Posts: 1684

 PostPosted: Wed Feb 09, 2011 11:12 am    Post subject: GCC and malloc Reply with quote Back to top

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!
 
View user's profile Send private message Send e-mail
SubDrag
Administrator
Administrator


Joined: 16 Aug 2006
Posts: 6118

 PostPosted: Tue Feb 15, 2011 4:06 am    Post subject: Reply with quote Back to top

I've mainly seen malloc, but yeah that doesn't seem right...seems like a PC problem or your compiler is off.
 
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ShootersForever.com Forum Index -> Computer SOS All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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

Cobalt 2.0 BB theme/template by Jakob Persson.
Copyright © 2002-2004 Jakob Persson


Powered by BB © 01, 02 BB Group

 


Please Visit My Other Sites: GoldenEyeForever.com | GrandTheftAutoForever.com

Got kids? Check out my Dora The Explorer site with games and coloring pages!

Our forums feature Nintendo 64 games, GoldenEye 007 N64 New Maps and Missions, GoldenEye Cheats, N64 Emulator, Gameshark, GoldenEye Multiplayer and more!

[ Privacy Policy ]