Segmentation fault? Related to not casting or warning errors on compile? 
Author Message
 Segmentation fault? Related to not casting or warning errors on compile?



Quote:
> Hello all,

> I can't find anywhere in my program where I am putting this data here,
> so I can only put it down to one thing.... I am getting lots of
> warnings when I compile, here are three of them...

> parse.c:506: warning: assignment makes integer from pointer without a
> cast
> parse.c:526: warning: assignment makes integer from pointer without a
> cast
> parse.c:547: warning: assignment makes integer from pointer without a
> cast

> This warning is repeated about 500 times due to one sub routine just
> being copied and slightly modified many times.

This is an excellent way to write huge fragile programs.

--
Chris "surely 'abstraction' isn't a 4-letter word?" Dollin
C FAQs at: http://www.*-*-*.com/



Sat, 24 Aug 2002 03:00:00 GMT  
 Segmentation fault? Related to not casting or warning errors on compile?

Quote:

> Hello all,

> I'm having trouble again, this time with memory... I have declared a
> character array line[10][MAXSEND], where MAXSEND is 4000. (Yeah I know
> it's wasteful... ;).

> I have a sub that splits another string into parts that fit in that
> one. I've determined that some how, for some reason the last two
> elements are containing important program data, as the program crash's
> with a SEGV when I overwrite the data.

> I can't find anywhere in my program where I am putting this data here,
> so I can only put it down to one thing.... I am getting lots of
> warnings when I compile, here are three of them...

> parse.c:506: warning: assignment makes integer from pointer without a
> cast
> parse.c:526: warning: assignment makes integer from pointer without a
> cast
> parse.c:547: warning: assignment makes integer from pointer without a
> cast

> This warning is repeated about 500 times due to one sub routine just
> being copied and slightly modified many times.

> 547 (nb not all the lines are like this) is

> aUser[aSocket[iCount]->userarray]->email[strlen(line[0])] = NULL;

> caUser is defined by... struct tUser ** aUser=NULL;
> aSocket is defined by... struct tSocket ** aSocket=NULL;

> aSocket[iCount]->userarray is an unsigned long and iCount is an
> unsigned integer.

<snip>

It would have been very useful to know what *email* is.  (I will assume,
perhaps wrongly so, that it was defined char *email or something
similar.  If this isn't the case, ignore the rest of this post.)

In this line
aUser[aSocket[iCount]->userarray]->email[strlen(line[0])] = NULL;
you are telling the compiler to let ...->email[strlen(line[0])] get the
value NULL.  However, this is a character and not a pointer.  Certain
implementations #define NULL as (void *)0 and others simply as 0.  I
assume that your compiler uses the first definition, whereas the
original program was compiled with the second one.  Hence, you are
receiving the error and they didn't.  This is their fault -- not yours
or your compiler's.

It is simple but tedious to fix this error.  One way to rectify the
problem is to change *every* line where that appears to either
aUser[aSocket[iCount]->userarray]->email[strlen(line[0])] = 0;
or
aUser[aSocket[iCount]->userarray]->email[strlen(line[0])] = '\0';.
Both are valid, but the second one shows (somewhat more) clearly that we
are indeed talking about an array of char and not of int or anything
else.

Hope this helps!

Cheers,
Selim



Sun, 25 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Segmentation fault? Related to not casting or warning errors on compile?

2. Segmentation fault related w/ malloc

3. Segmentation fault and parse error

4. Segmentation fault vs Bus error

5. bus error/segmentation fault

6. Segmentation Fault/Bus Error

7. bus error--> segmentation fault

8. Cast warning (not an easy one)

9. Page fault when compile using Release mode but not Debug mode

10. STL does not compile cleanly using warning level 4 (/W4)

11. Casting iterators - compile error

12. Warnings appearing as error messages when compiling with MFC

 

 
Powered by phpBB® Forum Software