coredump when read memory in AIX

P

peng qiu

Hi, I met "core" in my program. Help needed to review my source code.
Detail environment:
OS: AIX 5.2.0.0 (64bit)
Complier: VisualAge C 6
-----example.c-----------
#include <stdio.h>

int main()
{
int i = 0;
char *p = "abcd";
for (i = 0; i < 10000; i++) {
printf("p[%d] = %d\n", i, p);
}
}

when i reached 2750, program coredump.
I know that "write" can result in segmentation fault, what about
"read"?
Thank you very much for your help.
 
V

Vladimir Jovic

peng said:
Hi, I met "core" in my program. Help needed to review my source code.
Detail environment:
OS: AIX 5.2.0.0 (64bit)
Complier: VisualAge C 6
-----example.c-----------
#include <stdio.h>

int main()
{
int i = 0;
char *p = "abcd";
for (i = 0; i < 10000; i++) {
printf("p[%d] = %d\n", i, p);
}
}

when i reached 2750, program coredump.
I know that "write" can result in segmentation fault, what about
"read"?
Thank you very much for your help.


Read this:
http://en.wikipedia.org/wiki/Memory_protection
 
R

red floyd

peng said:
Hi, I met "core" in my program. Help needed to review my source code.
Detail environment:
OS: AIX 5.2.0.0 (64bit)
Complier: VisualAge C 6
-----example.c-----------
#include <stdio.h>

int main()
{
int i = 0;
char *p = "abcd";
for (i = 0; i < 10000; i++) {
printf("p[%d] = %d\n", i, p);
}
}

when i reached 2750, program coredump.
I know that "write" can result in segmentation fault, what about
"read"?
Thank you very much for your help.


Once you access p[6], all bets are off. You have undefined behavior.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top