[comp.lang.c] (Question) Wired runtime error

S

Sleepy

Dear Support

When i run my program, i get the following:

"Exiting due to signal SIGSEGV
General Protection Fault at eip=0001cdc0
eax=00000009 ebx=000ca110 ecx=000ca110 edx=00000000 esi=0000160e
edi=00000009 ebp=000c99f8 esp=000c99e0 program=C:\TEST.EXE
cs: sel=01a7 base=029d0000 limit=000dffff
ds: sel=01af base=029d0000 limit=000dffff
es: sel=01af base=029d0000 limit=000dffff
fs: sel=017f base=00006ca0 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=029d0000 limit=000dffff
App stack: [000c9aac..00049aac] Excetn stack: [00049a00..00047ac0]

Call frame traceback EIPs:
0x0001cdc0
0x0001c46e
0x00001757
0x00005548
"

That makes no sense at all to me... Do you know what the error is?

Thanks.
 
B

Ben Bacarisse

Sleepy said:
When i run my program, i get the following:

"Exiting due to signal SIGSEGV
General Protection Fault at eip=0001cdc0
eax=00000009 ebx=000ca110 ecx=000ca110 edx=00000000 esi=0000160e
edi=00000009 ebp=000c99f8 esp=000c99e0 program=C:\TEST.EXE
cs: sel=01a7 base=029d0000 limit=000dffff
ds: sel=01af base=029d0000 limit=000dffff
es: sel=01af base=029d0000 limit=000dffff
fs: sel=017f base=00006ca0 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=029d0000 limit=000dffff
App stack: [000c9aac..00049aac] Excetn stack: [00049a00..00047ac0]

Call frame traceback EIPs:
0x0001cdc0
0x0001c46e
0x00001757
0x00005548
"

That makes no sense at all to me... Do you know what the error is?

A general protection fault means that your program tried to access an
invalid address. This can be the result of a huge number of different
programming errors -- so many that it's probably unwise to suggest any
particular ones. A debugger will be able to turn those addresses (in
particular the stacked EIPs) into lines of code so you can see where the
exception is raised. If you are lucky, this will be near the source of
the error. If you are unlucky, it will simply where some earlier error
shows up.
 
J

J. J. Farrell

Sleepy said:
Dear Support

Who he?
When i run my program, i get the following:

"Exiting due to signal SIGSEGV
General Protection Fault at eip=0001cdc0
eax=00000009 ebx=000ca110 ecx=000ca110 edx=00000000 esi=0000160e
edi=00000009 ebp=000c99f8 esp=000c99e0 program=C:\TEST.EXE
cs: sel=01a7 base=029d0000 limit=000dffff
ds: sel=01af base=029d0000 limit=000dffff
es: sel=01af base=029d0000 limit=000dffff
fs: sel=017f base=00006ca0 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=029d0000 limit=000dffff
App stack: [000c9aac..00049aac] Excetn stack: [00049a00..00047ac0]

Call frame traceback EIPs:
0x0001cdc0
0x0001c46e
0x00001757
0x00005548
"

That makes no sense at all to me... Do you know what the error is?

Thanks.

Yes, there's most likely something wrong in your program.
http://www.catb.org/~esr/faqs/smart-questions.html may help.
 
H

Hans Vlems

Dear Support

When i run my program, i get the following:

"Exiting due to signal SIGSEGV
General Protection Fault at eip=0001cdc0 [snip]

That makes no sense at all to me... Do you know what the error is?

Thanks.

Without the program source there's no way to tell what went wrong.
Guessing might help you but, more likely, confuse you even more.
Hans
 
K

Kenny McCormack

Dear Support

When i run my program, i get the following:

"Exiting due to signal SIGSEGV
General Protection Fault at eip=0001cdc0 [snip]

That makes no sense at all to me... Do you know what the error is?

Thanks.

Without the program source there's no way to tell what went wrong.
Guessing might help you but, more likely, confuse you even more.
Hans

That's not true. The way newsgroups run nowadays, posting the source is
the last thing you want to do.

--

Some of the more common characteristics of Asperger syndrome include:

* Inability to think in abstract ways (eg: puns, jokes, sarcasm, etc)
* Difficulties in empathising with others
* Problems with understanding another person's point of view
* Hampered conversational ability
* Problems with controlling feelings such as anger, depression
and anxiety
* Adherence to routines and schedules, and stress if expected routine
is disrupted
* Inability to manage appropriate social conduct
* Delayed understanding of sexual codes of conduct
* A narrow field of interests. For example a person with Asperger
syndrome may focus on learning all there is to know about
baseball statistics, politics or television shows.
* Anger and aggression when things do not happen as they want
* Sensitivity to criticism
* Eccentricity
* Behaviour varies from mildly unusual to quite aggressive
and difficult
 
P

Peter Nilsson

Sleepy said:
Dear Support

When i run my program, i get the following:

"Exiting due to signal SIGSEGV
That makes no sense at all to me... Do you know what the error is?

I did a calculation that yielded -42 when it was supposed to
yield a positive number. It makes no sense at all to me...
Do you know what the error is?

You're asking us to find Wally/Waldo in a picture that doesn't
contain Wally/Waldo. Show the minimum compilable source code
that exhibits the problem.
 
S

Sleepy

Thanks... here is the source-code.

#include "stdhdrs.h"
void main()
{
char *buf=malloc(SIZE_MAX*sizeof(char));
printf("Enter your name:");
scanf("%s",buf);
printf("Hello %s",buf);
}
 
K

Keith Thompson

Sleepy said:
Thanks... here is the source-code.

#include "stdhdrs.h"
void main()
{
char *buf=malloc(SIZE_MAX*sizeof(char));
printf("Enter your name:");
scanf("%s",buf);
printf("Hello %s",buf);
}

Please don't top-post. See:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

"stdhdrs.h" is not a standard header. If you want your code to be
portable, you need:
#include <stdlib.h> /* for malloc */
#include <stdio.h> /* for printf and scanf */
#include <limits.h> /* for SIZE_MAX -- but see below */

"void main()" is wrong. It should be "int main(void)". If your book
tells you that "void main()" is correct, get a better book.

SIZE_MAX is the maximum possible value of type size_t. It's guaranteed
to be at least 65535, but is more likely to be 4294967295 on most
systems, or even 18446744073709551615 on 64-bit systems.

You really don't want to try to allocate that much memory.

sizeof(char) is guaranteed to be exactly 1. If you really wanted to
try to allocate SIZE_MAX bytes, you could write:

char *buf = malloc(SIZE_MAX);

If malloc() fails, it returns a null pointer to indicate that the memory
was not allocated. You should *always* check for this, and take some
action (perhaps just quitting the program with an error message) in
response to a failure. Since you probably just tried to allocate 4
gigabytes of memory, malloc() almost certainly failed, giving you a null
pointer that you try to use later. This is the cause of the symptom
you're seeing.

Since
printf("Enter you name:");
doesn't print a new-line, it doesn't guarantee that the output will
appear immediately. It probably does on your system, but to be sure
you can add
fflush(stdout);
after the printf.

Never use a "%s" format with scanf. It doesn't limit the number of
characters that the user can enter, and will attempt to store *all* of
them in the buffer. (Is that you used SIZE_MAX for malloc()?) There
are ways to restrict the size of the input. Also, "%s" reads a
blank-delimited word; if I enter "Keith Thompson", it will only store
"Keith" in the buffer. Consider using fgets() (*not* gets()) rather
than scanf().

printf("Hello %s",buf);
doesn't print a new-line. For various reasons, you should use:
printf("Hello %s\n", buf);

Finally, since main returns an int, you should add
return 0;
before the closing "}". There are circumstances where this isn't
required, but it's easier to always add it.

But hey, the lines with the curly braces were just fine!

You might find the comp.lang.c FAQ, <http://www.c-faq.com/>, a useful
resource.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top