Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] For C Experts

2006-03-31 by Robert Adsett

At 03:26 PM 3/30/06 +0000, dsidlauskas1 wrote:
>Consider the following code:
>
>============================
>char buf[]={1,2,3,4,5,6,7,8};
>int *ip, x[4];
>
>for (i=0; i<4; i++)
>     {
>     ip = (int *)&buf[i];
>     x[4]  = *ip;
>     }
>=============================

As I said earlier I was curious as to what lint (in may case PC-Lint) would 
make of this. So I added the following to one of my files

void check( void)
{
char buf[]={1,2,3,4,5,6,7,8};
int *ip, x[4];
int i;

for (i=0; i<4; i++)
     {
     ip = (int *)&buf[i];
     x[4]  = *ip;
     }
}

Fixing up the missing declaration for i ;) And I got the following 
errors.  I would never actually let this get to the compiler until I had 
cleaned these up.

     ip = (int *)&buf[i];
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  54  Note 927: cast from pointer
     to pointer

                |
     x[4]  = *ip;
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Warning 415: Likely access of
     out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference:
     file e:\cygwin\home\radsett\newlib-lpc\_close_r.c: line 55]

e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Info 831: Reference cited in
     prior message

|
}
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  57  Warning 550: Symbol 'x' (line
     49) not accessed

e:\cygwin\home\radsett\newlib-lpc\_close_r.c  49  Info 830: Location cited in
     prior message

|
}
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  57  Note 954: Pointer variable
     'ip' (line 49) could be declared as pointing to const

e:\cygwin\home\radsett\newlib-lpc\_close_r.c  49  Info 830: Location cited in
     prior message


/// Start of Pass 2 ///
                |
     x[4]  = *ip;
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Warning 415: Likely access of
     out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference:
     file e:\cygwin\home\radsett\newlib-lpc\_close_r.c: line 55]
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Info 831: Reference cited in
     prior message
                |
     x[4]  = *ip;
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Warning 415: Likely access of
     out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference:
     file e:\cygwin\home\radsett\newlib-lpc\_close_r.c: line 55]
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Info 831: Reference cited in
     prior message
                |
     x[4]  = *ip;
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Warning 415: Likely access of
     out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference:
     file e:\cygwin\home\radsett\newlib-lpc\_close_r.c: line 55]
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Info 831: Reference cited in
     prior message
                |
     x[4]  = *ip;
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Warning 415: Likely access of
     out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference:
     file e:\cygwin\home\radsett\newlib-lpc\_close_r.c: line 55]
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Info 831: Reference cited in
     prior message
                |
     x[4]  = *ip;
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Warning 415: Likely access of
     out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference:
     file e:\cygwin\home\radsett\newlib-lpc\_close_r.c: line 55]
e:\cygwin\home\radsett\newlib-lpc\_close_r.c  55  Info 831: Reference cited in
     prior message

Kudos to GCC for picking up the alignment issue explicitly, Lint only hints 
at it with the pointer to pointer cast warning.

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.