problem with SIGSEGV

bridged with qdn.public.qnxrtp.applications
Post Reply
Jorge Alonso

problem with SIGSEGV

Post by Jorge Alonso » Tue Jan 13, 2004 10:01 am

Hi!

I´m doing my first application, and I have a problem with SIGSEGV signal.

I debug my application and it runs correctly for hours, but when least
expected was caused an segmentation fault (SIGSEGV signal).
This error was produced when I try to write in a file.

The time the application is running is random (2, 3 , ... 10, 11 or 12, ...,
15 hours).

Can someone help me? Do you need the code?

Jorge

C. Scott

Re: problem with SIGSEGV

Post by C. Scott » Tue Jan 13, 2004 12:18 pm

If you are running QNX4 with Watcom you can start the dumper utility to give
you a dump file when a process terminates, and you can then use the Watcom
debugger to find what line of the program caused the segment violation.

--
C. Scott

"Jorge Alonso" <jalonso@ain.es> wrote in message
news:bu0dq9$hqv$1@inn.qnx.com...
Hi!

I´m doing my first application, and I have a problem with SIGSEGV signal.

I debug my application and it runs correctly for hours, but when least
expected was caused an segmentation fault (SIGSEGV signal).
This error was produced when I try to write in a file.

The time the application is running is random (2, 3 , ... 10, 11 or 12,
....,
15 hours).

Can someone help me? Do you need the code?

Jorge

C. Scott

Re: problem with SIGSEGV

Post by C. Scott » Tue Jan 13, 2004 12:21 pm

I forgot to mention that with QNX 6 (which is what you are probably running)
you should get a core file when a process crashes, and you can use gdb to
see what line caused the crash.

--
C. Scott




"C. Scott" <cscott@nospam.com> wrote in message
news:bu0nlh$n17$1@nntp.qnx.com...
If you are running QNX4 with Watcom you can start the dumper utility to
give
you a dump file when a process terminates, and you can then use the Watcom
debugger to find what line of the program caused the segment violation.

--
C. Scott

"Jorge Alonso" <jalonso@ain.es> wrote in message
news:bu0dq9$hqv$1@inn.qnx.com...
Hi!

I´m doing my first application, and I have a problem with SIGSEGV
signal.

I debug my application and it runs correctly for hours, but when least
expected was caused an segmentation fault (SIGSEGV signal).
This error was produced when I try to write in a file.

The time the application is running is random (2, 3 , ... 10, 11 or 12,
...,
15 hours).

Can someone help me? Do you need the code?

Jorge



Bill Caroselli

Re: problem with SIGSEGV

Post by Bill Caroselli » Tue Jan 13, 2004 1:47 pm

C. Scott <cscott@nospam.com> wrote:
CS > I forgot to mention that with QNX 6 (which is what you are probably running)
CS > you should get a core file when a process crashes, and you can use gdb to
CS > see what line caused the crash.

Also, be aware that you are probibly dereferencing a pointer that is
not (no longer) valid.

Dmitri Poustovalov

Re: problem with SIGSEGV

Post by Dmitri Poustovalov » Wed Jan 14, 2004 9:22 am

This line 'buffer = (unsigned char)malloc(80);' in FileCp() does fishy
casting to (unsigned char) instead of (unsigned char *). As result
'buffer' variable may point to somewhere else but not where you expect
it to. Sometimes you may damage data at that 'somewhere' location. And
maybe that's what causes the problem in WriteVibrations(). Sometimes
your 'buffer' pointer can not be dereferenced atall and you get SIGSEGV
at 'fwrite(buffer, 1, bytes, pfd);' line.

The line should be:
buffer = (unsigned char *)malloc(80);

-dp

Jorge Alonso wrote:
Hi!

First, I work with QNX 6.
Then, I know the function and line where is caused the crash. Always it is
produced in one of this functions (although in most cases it´s in the
first):

void WriteVibrations (FILE * f)
{
unsigned short i;
int vibr;
int *pVibr;
float mg, mv;

pVibr = &vibr;
for (i=0; i<NUM_CONVERSIONS; i++) {
mv = (5000 * g_aBufferVibr[g_nChannel] / 32768.0);
mg = (1000 * mv) / g_nSensitivity[g_nChannel];
vibr = (int)mg;
fwrite(pVibr, sizeof(int), 1, f); //here SIGSEGV
signal is produced!!!!!
}
}

int FileCp(char *szSourceFile, char *szDestFile)
{
FILE *pfo;
FILE *pfd;
int bytes;
unsigned char *buffer;

buffer = (unsigned char)malloc(80);
if (buffer != NULL) {
pfo = fopen(szSourceFile, "rb")
if (pfo != NULL) {
pfd = fopen(szDestFile, "wb")
if (pfd != NULL) {
while(1) {
bytes = fread(buffer, 1, 80, pfo);
if (bytes == 0) break;
fwrite(buffer, 1, bytes, pfd); //or here
SIGSEGV signal is produced!!!!!
}
fclose(pfd);
}
else {
fclose(pfo);
free(buffer);
return 1;
}
fclose(pfo);
}
else {
free(buffer);
return 1;
}
free(buffer);
}
return 0;
}

I think you want to say this:

FILE *f;
int *p;

....
fwrite(p, sizeof(char), 1, f); //the variable´s size doesn´t valid
....

when you say "you are probibly dereferencing a pointer that is not (no
longer) valid". Is it the case? If not, Can you explain me with an example?



"Bill Caroselli" <qtps@earthlink.net> escribió en el mensaje
news:bu0ssp$s31$2@inn.qnx.com...

C. Scott <cscott@nospam.com> wrote:
CS > I forgot to mention that with QNX 6 (which is what you are probably

running)

CS > you should get a core file when a process crashes, and you can use

gdb to

CS > see what line caused the crash.

Also, be aware that you are probibly dereferencing a pointer that is
not (no longer) valid.



Jorge Alonso

Re: problem with SIGSEGV

Post by Jorge Alonso » Wed Jan 14, 2004 10:02 am

Hi!

First, I work with QNX 6.
Then, I know the function and line where is caused the crash. Always it is
produced in one of this functions (although in most cases it´s in the
first):

void WriteVibrations (FILE * f)
{
unsigned short i;
int vibr;
int *pVibr;
float mg, mv;

pVibr = &vibr;
for (i=0; i<NUM_CONVERSIONS; i++) {
mv = (5000 * g_aBufferVibr[g_nChannel] / 32768.0);
mg = (1000 * mv) / g_nSensitivity[g_nChannel];
vibr = (int)mg;
fwrite(pVibr, sizeof(int), 1, f); //here SIGSEGV
signal is produced!!!!!
}
}

int FileCp(char *szSourceFile, char *szDestFile)
{
FILE *pfo;
FILE *pfd;
int bytes;
unsigned char *buffer;

buffer = (unsigned char)malloc(80);
if (buffer != NULL) {
pfo = fopen(szSourceFile, "rb")
if (pfo != NULL) {
pfd = fopen(szDestFile, "wb")
if (pfd != NULL) {
while(1) {
bytes = fread(buffer, 1, 80, pfo);
if (bytes == 0) break;
fwrite(buffer, 1, bytes, pfd); //or here
SIGSEGV signal is produced!!!!!
}
fclose(pfd);
}
else {
fclose(pfo);
free(buffer);
return 1;
}
fclose(pfo);
}
else {
free(buffer);
return 1;
}
free(buffer);
}
return 0;
}

I think you want to say this:

FILE *f;
int *p;

....
fwrite(p, sizeof(char), 1, f); //the variable´s size doesn´t valid
....

when you say "you are probibly dereferencing a pointer that is not (no
longer) valid". Is it the case? If not, Can you explain me with an example?



"Bill Caroselli" <qtps@earthlink.net> escribió en el mensaje
news:bu0ssp$s31$2@inn.qnx.com...
C. Scott <cscott@nospam.com> wrote:
CS > I forgot to mention that with QNX 6 (which is what you are probably
running)
CS > you should get a core file when a process crashes, and you can use
gdb to
CS > see what line caused the crash.

Also, be aware that you are probibly dereferencing a pointer that is
not (no longer) valid.

Dmitri Poustovalov

Re: problem with SIGSEGV

Post by Dmitri Poustovalov » Fri Jan 16, 2004 8:59 am

Jorge Alonso wrote:
Sorry, I forgot to write '*' in the line 'buffer = (unsigned char
*)malloc(80);

Can you explain me the meaning of 'dereferencing a pointer'?
http://www.google.ca/search?q=dereferen ... arch&meta=

Thanks.


"Dmitri Poustovalov" <pdmitri@bbbiiigggfffoooooottt.com> escribió en el
mensaje news:40050A5D.80502@bbbiiigggfffoooooottt.com...

This line 'buffer = (unsigned char)malloc(80);' in FileCp() does fishy
casting to (unsigned char) instead of (unsigned char *). As result
'buffer' variable may point to somewhere else but not where you expect
it to. Sometimes you may damage data at that 'somewhere' location. And
maybe that's what causes the problem in WriteVibrations(). Sometimes
your 'buffer' pointer can not be dereferenced atall and you get SIGSEGV
at 'fwrite(buffer, 1, bytes, pfd);' line.

The line should be:
buffer = (unsigned char *)malloc(80);

-dp

Jorge Alonso wrote:

Hi!

First, I work with QNX 6.
Then, I know the function and line where is caused the crash. Always it

is

produced in one of this functions (although in most cases it´s in the
first):

void WriteVibrations (FILE * f)
{
unsigned short i;
int vibr;
int *pVibr;
float mg, mv;

pVibr = &vibr;
for (i=0; i<NUM_CONVERSIONS; i++) {
mv = (5000 * g_aBufferVibr[g_nChannel] / 32768.0);
mg = (1000 * mv) / g_nSensitivity[g_nChannel];
vibr = (int)mg;
fwrite(pVibr, sizeof(int), 1, f); //here

SIGSEGV

signal is produced!!!!!
}
}

int FileCp(char *szSourceFile, char *szDestFile)
{
FILE *pfo;
FILE *pfd;
int bytes;
unsigned char *buffer;

buffer = (unsigned char)malloc(80);
if (buffer != NULL) {
pfo = fopen(szSourceFile, "rb")
if (pfo != NULL) {
pfd = fopen(szDestFile, "wb")
if (pfd != NULL) {
while(1) {
bytes = fread(buffer, 1, 80, pfo);
if (bytes == 0) break;
fwrite(buffer, 1, bytes, pfd); //or

here

SIGSEGV signal is produced!!!!!
}
fclose(pfd);
}
else {
fclose(pfo);
free(buffer);
return 1;
}
fclose(pfo);
}
else {
free(buffer);
return 1;
}
free(buffer);
}
return 0;
}

I think you want to say this:

FILE *f;
int *p;

....
fwrite(p, sizeof(char), 1, f); //the variable´s size doesn´t

valid

....

when you say "you are probibly dereferencing a pointer that is not (no
longer) valid". Is it the case? If not, Can you explain me with an

example?



"Bill Caroselli" <qtps@earthlink.net> escribió en el mensaje
news:bu0ssp$s31$2@inn.qnx.com...


C. Scott <cscott@nospam.com> wrote:
CS > I forgot to mention that with QNX 6 (which is what you are probably

running)


CS > you should get a core file when a process crashes, and you can use

gdb to


CS > see what line caused the crash.

Also, be aware that you are probibly dereferencing a pointer that is
not (no longer) valid.






Jorge Alonso

Re: problem with SIGSEGV

Post by Jorge Alonso » Fri Jan 16, 2004 10:37 am

Sorry, I forgot to write '*' in the line 'buffer = (unsigned char
*)malloc(80);

Can you explain me the meaning of 'dereferencing a pointer'?

Thanks.


"Dmitri Poustovalov" <pdmitri@bbbiiigggfffoooooottt.com> escribió en el
mensaje news:40050A5D.80502@bbbiiigggfffoooooottt.com...
This line 'buffer = (unsigned char)malloc(80);' in FileCp() does fishy
casting to (unsigned char) instead of (unsigned char *). As result
'buffer' variable may point to somewhere else but not where you expect
it to. Sometimes you may damage data at that 'somewhere' location. And
maybe that's what causes the problem in WriteVibrations(). Sometimes
your 'buffer' pointer can not be dereferenced atall and you get SIGSEGV
at 'fwrite(buffer, 1, bytes, pfd);' line.

The line should be:
buffer = (unsigned char *)malloc(80);

-dp

Jorge Alonso wrote:
Hi!

First, I work with QNX 6.
Then, I know the function and line where is caused the crash. Always it
is
produced in one of this functions (although in most cases it´s in the
first):

void WriteVibrations (FILE * f)
{
unsigned short i;
int vibr;
int *pVibr;
float mg, mv;

pVibr = &vibr;
for (i=0; i<NUM_CONVERSIONS; i++) {
mv = (5000 * g_aBufferVibr[g_nChannel] / 32768.0);
mg = (1000 * mv) / g_nSensitivity[g_nChannel];
vibr = (int)mg;
fwrite(pVibr, sizeof(int), 1, f); //here
SIGSEGV
signal is produced!!!!!
}
}

int FileCp(char *szSourceFile, char *szDestFile)
{
FILE *pfo;
FILE *pfd;
int bytes;
unsigned char *buffer;

buffer = (unsigned char)malloc(80);
if (buffer != NULL) {
pfo = fopen(szSourceFile, "rb")
if (pfo != NULL) {
pfd = fopen(szDestFile, "wb")
if (pfd != NULL) {
while(1) {
bytes = fread(buffer, 1, 80, pfo);
if (bytes == 0) break;
fwrite(buffer, 1, bytes, pfd); //or
here
SIGSEGV signal is produced!!!!!
}
fclose(pfd);
}
else {
fclose(pfo);
free(buffer);
return 1;
}
fclose(pfo);
}
else {
free(buffer);
return 1;
}
free(buffer);
}
return 0;
}

I think you want to say this:

FILE *f;
int *p;

....
fwrite(p, sizeof(char), 1, f); //the variable´s size doesn´t
valid
....

when you say "you are probibly dereferencing a pointer that is not (no
longer) valid". Is it the case? If not, Can you explain me with an
example?



"Bill Caroselli" <qtps@earthlink.net> escribió en el mensaje
news:bu0ssp$s31$2@inn.qnx.com...

C. Scott <cscott@nospam.com> wrote:
CS > I forgot to mention that with QNX 6 (which is what you are probably

running)

CS > you should get a core file when a process crashes, and you can use

gdb to

CS > see what line caused the crash.

Also, be aware that you are probibly dereferencing a pointer that is
not (no longer) valid.





Jorge Alonso

Re: problem with SIGSEGV

Post by Jorge Alonso » Mon Jan 19, 2004 8:03 am

Thanks, Jorge
..


"Dmitri Poustovalov" <pdmitri@bbbiiigggfffoooooottt.com> escribió en el
mensaje news:4007A7FF.9090308@bbbiiigggfffoooooottt.com...
Jorge Alonso wrote:
Sorry, I forgot to write '*' in the line 'buffer = (unsigned char
*)malloc(80);

Can you explain me the meaning of 'dereferencing a pointer'?


http://www.google.ca/search?q=dereferen ... g&ie=UTF-8&
oe=UTF-8&hl=en&btnG=Google+Search&meta=


Thanks.


"Dmitri Poustovalov" <pdmitri@bbbiiigggfffoooooottt.com> escribió en el
mensaje news:40050A5D.80502@bbbiiigggfffoooooottt.com...

This line 'buffer = (unsigned char)malloc(80);' in FileCp() does fishy
casting to (unsigned char) instead of (unsigned char *). As result
'buffer' variable may point to somewhere else but not where you expect
it to. Sometimes you may damage data at that 'somewhere' location. And
maybe that's what causes the problem in WriteVibrations(). Sometimes
your 'buffer' pointer can not be dereferenced atall and you get SIGSEGV
at 'fwrite(buffer, 1, bytes, pfd);' line.

The line should be:
buffer = (unsigned char *)malloc(80);

-dp

Jorge Alonso wrote:

Hi!

First, I work with QNX 6.
Then, I know the function and line where is caused the crash. Always it

is

produced in one of this functions (although in most cases it´s in the
first):

void WriteVibrations (FILE * f)
{
unsigned short i;
int vibr;
int *pVibr;
float mg, mv;

pVibr = &vibr;
for (i=0; i<NUM_CONVERSIONS; i++) {
mv = (5000 * g_aBufferVibr[g_nChannel] / 32768.0);
mg = (1000 * mv) / g_nSensitivity[g_nChannel];
vibr = (int)mg;
fwrite(pVibr, sizeof(int), 1, f); //here

SIGSEGV

signal is produced!!!!!
}
}

int FileCp(char *szSourceFile, char *szDestFile)
{
FILE *pfo;
FILE *pfd;
int bytes;
unsigned char *buffer;

buffer = (unsigned char)malloc(80);
if (buffer != NULL) {
pfo = fopen(szSourceFile, "rb")
if (pfo != NULL) {
pfd = fopen(szDestFile, "wb")
if (pfd != NULL) {
while(1) {
bytes = fread(buffer, 1, 80, pfo);
if (bytes == 0) break;
fwrite(buffer, 1, bytes, pfd); //or

here

SIGSEGV signal is produced!!!!!
}
fclose(pfd);
}
else {
fclose(pfo);
free(buffer);
return 1;
}
fclose(pfo);
}
else {
free(buffer);
return 1;
}
free(buffer);
}
return 0;
}

I think you want to say this:

FILE *f;
int *p;

....
fwrite(p, sizeof(char), 1, f); //the variable´s size doesn´t

valid

....

when you say "you are probibly dereferencing a pointer that is not (no
longer) valid". Is it the case? If not, Can you explain me with an

example?



"Bill Caroselli" <qtps@earthlink.net> escribió en el mensaje
news:bu0ssp$s31$2@inn.qnx.com...


C. Scott <cscott@nospam.com> wrote:
CS > I forgot to mention that with QNX 6 (which is what you are
probably

running)


CS > you should get a core file when a process crashes, and you can
use

gdb to


CS > see what line caused the crash.

Also, be aware that you are probibly dereferencing a pointer that is
not (no longer) valid.








Post Reply

Return to “qdn.public.qnxrtp.applications”