Character pointer c core dump

Scott Henry scotth at corp.sgi.com
Thu Apr 12 18:20:17 AEST 1990



> What's wrong with this picture, or what's wrong with this
> cc compiler?  The following dumps core at *lp=5:
>  
> char buf[1024];
>  
main()
>  
> {
>  
>   long *lp;
>  
>   int i;
>  
>  
>     lp = (long *)&buf[6];
>  
>     *lp = 5;
>
>     printf("%ld\n", *lp);
>
>
>}
>
> However....  If you replace the &buf[6] with &buf[0], it
> works the way you would expect and prints 5 to the screen.
> Looks like a bug?
> Thanks for any help you can give me.

This code came from and works on a VAX, right :-)? The MIPS processor can
only access long data on long boundaries. Assuming that the buffer starts
at a longword boundary, offsets that are on a longword boundary ([0], [4],
[8], etc) will work, any other offset will cause a segv and core dump. If
lp where a short, then offsets that are a multiple of a short (0, 2, 4, 6,
etc) would work.  (VAX's can access any sized data at any offset). Hope
this helps!

>                              Tim Buxton
>                              OptiMetrics, Inc.
>                              Tim_Buxton at um.cc.umich.edu

--
 Scott Henry <scotth at sgi.com> | Traveller on Dragon Wings
 Information Services,        |
 Silicon Graphics, Inc        | These are my Opinions only! Whose else?



More information about the Comp.sys.sgi mailing list