A
andreas
Hello Newsgroup,
I've got a problem with a function that should return a pointer to the
beginning of a string or NULL. like this:
char* getString(void);
The problem is, that the function seems to be bugy. It sometimes returns a
pointer, that must not be derefered, if I try, I get a segmentation fault
or something like this. This pointer is not NULL.
How can I test, if I can access the String whithout a programm crash? A try
catch block does not work.
Just to illustrate:
char* getString(void){ //this is just to create a bad return
char* null = NULL; //the real bugy function is in a library
return &null[1]; //i have to use
}
int main(void) {
char* badPtr = getString();
if(badPtr == NULL) {
printf("NULL Pointer\n"); // this does not happen
} else {
printf("Not NULL Pointer\n");
printf("Value: %i\n",*badPtr); // program crashes here
}
}
I had this Problems under Windows whis cygwin/gcc and borland bcc.
I think i can imagine why, but how can i solve it?
thanks
I've got a problem with a function that should return a pointer to the
beginning of a string or NULL. like this:
char* getString(void);
The problem is, that the function seems to be bugy. It sometimes returns a
pointer, that must not be derefered, if I try, I get a segmentation fault
or something like this. This pointer is not NULL.
How can I test, if I can access the String whithout a programm crash? A try
catch block does not work.
Just to illustrate:
char* getString(void){ //this is just to create a bad return
char* null = NULL; //the real bugy function is in a library
return &null[1]; //i have to use
}
int main(void) {
char* badPtr = getString();
if(badPtr == NULL) {
printf("NULL Pointer\n"); // this does not happen
} else {
printf("Not NULL Pointer\n");
printf("Value: %i\n",*badPtr); // program crashes here
}
}
I had this Problems under Windows whis cygwin/gcc and borland bcc.
I think i can imagine why, but how can i solve it?
thanks