Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
R2k
Posts: 16 Joined: Fri Mar 17, 2006 10:49 am
Location: México
Post
by R2k » Thu Mar 23, 2006 5:06 pm
well ... i was trying and trying and trying and well ..
Code: Select all
int createConsole(char* origin){
int result=0;
char* realpath='\0';
sprintf(realpath,origin); <------------------------------Crash Here!
strcat(realpath,"/img/console_bg.png"); <----------------and here
printf("path: %s", realpath);
//printf("Helloo!!!!!!!!");
result=readPNG(realpath);
//printf("result=%i",result);
return(result);
}
compiles and links OK, but when i run it crash in the sprintf but is the same with strcat , strcpy, snprintf ( i'm using newlib ).
i want to know your opinion about this ....
i know a solution for this !!! but ... it's odd ...
PSP FW v2.6 owner
Raphael
Posts: 646 Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:
Post
by Raphael » Thu Mar 23, 2006 6:39 pm
You can't initialize a string like this
char* realpath='\0';
What this does, is just initialize a pointer to a char struct and by setting it to '\0' you make it null pointer. Accessing this will no matter what crash your program.
Use this instead:
char realpath[256];
realpath = '\0';
hubevolution
Posts: 32 Joined: Wed Mar 17, 2004 6:59 pm
Post
by hubevolution » Thu Mar 23, 2006 6:58 pm
in general ... you need to allocate enough memory for the realpath variable to contain the maximum lenght possible expected for origin variable.
and realpath must be defined like :
Code: Select all
char realpath[MAX_ORIGIN_LENGTH];
in this case a path can be 255 max as raphael correctly stated :)
__count
Posts: 22 Joined: Thu Mar 23, 2006 8:40 pm
Post
by __count » Thu Mar 23, 2006 8:46 pm
Raphael wrote:
char realpath[256];
realpath = '\0';
That won't compile.
Either do
*realpath = '\0';
or
realpath[0] = '\0';
Raphael
Posts: 646 Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:
Post
by Raphael » Fri Mar 24, 2006 2:13 am
__count wrote: Raphael wrote:
char realpath[256];
realpath = '\0';
That won't compile.
Either do
*realpath = '\0';
or
realpath[0] = '\0';
Jup, right, forgot that [0] in a hurry :) thanks
R2k
Posts: 16 Joined: Fri Mar 17, 2006 10:49 am
Location: México
Post
by R2k » Sat Mar 25, 2006 5:34 am
tnx every1. i solved my prob. hehehehe
PSP FW v2.6 owner