* Segmentation Violation
@ 1996-11-06 5:00 Nader Behzad
1996-11-07 5:00 ` Jon Reeves
0 siblings, 1 reply; 2+ messages in thread
From: Nader Behzad @ 1996-11-06 5:00 UTC (permalink / raw)
Hi all,
Could anyone tell me if I am doing something wrong here or is it
the compiler:
char *tempstring;
tempstring = (char *)Malloc(256*sizeof(char));
char_count = strlen(angle_file);
tempstring = strrchr(angle_file, '/');
if (tempstring != NULL) {
tempstring++;
}
i = (char_count - strlen(tempstring)); /* <-------- A */
strncpy(temp, angle_file, i);
temp[i] = '\0';
"tempstring" is NULL and this causes the program to crash at point A.
The strlen result for NULL should be 0 right??
I don't have this problem under SUN_OS or Solaris platforms.
Thank you,
Sincerely,
Nader
--
---------------------------------------------------------------------
| |
| Nader T. Behzad |
| e-mail: nbehzad@ee.ualberta.ca |
| WWW: http://www.ee.ualberta.ca/~nbehzad |
| |
|===================================================================|
| |
| "Whatever you do will be insignificant, but it is very |
| important that you do it." --Mahatma Gandhi |
| |
---------------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Segmentation Violation
1996-11-06 5:00 Segmentation Violation Nader Behzad
@ 1996-11-07 5:00 ` Jon Reeves
0 siblings, 0 replies; 2+ messages in thread
From: Jon Reeves @ 1996-11-07 5:00 UTC (permalink / raw)
In article <55qg8v$tdi@pulp.ucs.ualberta.ca>, nbehzad@ee.ualberta.ca (Nader Behzad) writes:
...
|> tempstring = (char *)Malloc(256*sizeof(char));
...
|> i = (char_count - strlen(tempstring)); /* <-------- A */
...
|> "tempstring" is NULL and this causes the program to crash at point A.
The strlen function is only defined on pointers to strings.
NULL is not a pointer to a string.
--
Jon Reeves Digital UNIX Software Group reeves@zk3.dec.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-11-07 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-11-06 5:00 Segmentation Violation Nader Behzad
1996-11-07 5:00 ` Jon Reeves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox