On Sun, Apr 26, 2009 at 10:07:36PM +0200, Roland Mainz wrote:
> Fedor Sergeev wrote:
> > On Fri, Apr 24, 2009 at 08:43:55PM +0200, Roland Mainz wrote:
> > > Chris Quenelle wrote:
> > > > Roland Mainz wrote:
> > > > > Does Sun Studio 12 have a warning for statements like...
> > > > > -- snip --
> > > > > int pd;
> > > > > char *ptr1,
> > > > >      *ptr2;
> > > > > /* ... */
> > > > > pd = ptr2-ptr1;
> > > > > -- snip --
> > > > > ... on 64bit targets ?
> > > > >
> > > > > I've spend today some hours to dig-out this kind of bug where a 
> > > > > pointer
> > > > > difference (32bit on 32bit SPARC and 64bit on 64bit SPARC, e.g. a
> > > > > |ptrdiff_t|) is stored in an |int| (32bit integer) the loss of bits
> > > > > trigged a malfunction...
> > > > > ... somehow I was wondering why Sun Studio didn't warn about this.
> > > >
> > > > There's a chapter in the C user's guide about porting programs
> > > > from 32-bits to 64-bits.  It mentions a lint flag
> > > >
> > > >    -errchk=longptr64 flag checks assignments of pointer
> > > >    expressions and long integer expressions to plain
> > > >    integers, even when explicit casts are used.
> > > >
> > > > http://docs.sun.com/app/docs/doc/819-5265/bjami?a=view
> > >
> > > After some hacking with "lint vs. libshell" it seems that "lint" doesn't
> > > complain about the issue even when -errchk=%all is enabled... ;-(
> > 
> > That does not agree with my experience:
> > 
> > ] cat ptrdiff.c
> >         int pd;
> >         char *ptr1,
> >              *ptr2;
> >         pd = ptr2-ptr1;
> > 
> >         return pd;
> > }
> > ] lint -V ptrdiff.c -errchk=%all -c
> > lint: Sun C 5.9 SunOS_i386 Patch 124868-08 2008/11/25
> > lint: Sun C 5.9 SunOS_i386 Patch 124868-08 2008/11/25
> > (5) warning: assignment of 64-bit integer to 32-bit integer
> > (5) warning: variable may be used before set: ptr2
> > (5) warning: possible ptrdiff_t overflow
> 
> What is the name of the "error tag" for this warning ?
> 
> > (5) warning: variable may be used before set: ptr1
> > ]
> 
> Can you go to usr/src/lib/libshell/amd64/ and run $ make lintcheck #
> there, please ? I don't get this warning there but there are several

make lintcheck
results in a lint run that has

-erroff=E_ASSIGN_INT_TO_SMALL_INT

(and other -erroffs like E_PASS_INT_TO_SMALL_INT, E_CAST_INT_TO_SMALL_INT).

Thus it is just switching off this particular diagnostics.

After adding -errchk=%all -erroff=%none 

] make lintcheck 2>&1 | grep E_ASSIGN_INT_TO_SMALL_INT
"../common/bltins/read.c", line 147: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 153: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 158: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 179: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 286: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 300: warning: assignment of 32-bit integer to 
8-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 302: warning: assignment of 32-bit integer to 
8-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 340: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 344: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 348: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 356: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 356: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 359: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 378: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 399: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 414: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 426: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 428: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 445: warning: assignment of 32-bit integer to 
8-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 479: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 542: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 544: warning: assignment of 64-bit integer to 
32-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
"../common/bltins/read.c", line 667: warning: assignment of 32-bit integer to 
16-bit integer (E_ASSIGN_INT_TO_SMALL_INT)
]

Seems to be enough for starters ;)

regards,
  Fedor.


> statements (e.g.
> http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libshell/common/bltins/read.c#359
> - "m = (end - var) + (c - (end - cur));") which are currently causing
> problems with string data >= 2GB because the calculations use |int|
> instead of |ptrdiff_t| (this is going to be fixed with the next
> ksh93-integration update but I'd like to be sure that we caught all
> incarnations of this kind of bug).
> 
> "lint" and "cc" versions are:
> -- snip --
> $ cc
> -V                                                                            
>                             
> cc: Sun C 5.9 SunOS_i386 Patch 124868-07 2008/10/07
> usage: cc [ options] files.  Use 'cc -flags' for details
> $ lint
> -V                                                                            
>                           
> lint: Sun C 5.9 SunOS_i386 Patch 124868-07 2008/10/07
> usage: lint [ options] files.  Use 'lint -flags' for details
> -- snip --
> 
> ----
> 
> Bye,
> Roland
> 
> -- 
>   __ .  . __
>  (o.\ \/ /.o) roland.mainz at nrubsig.org
>   \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
>   /O /==\ O\  TEL +49 641 3992797
>  (;O/ \/ \O;)

Reply via email to