NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/43234: lint warns about perfectly good casts

>Number:         43234
>Category:       toolchain
>Synopsis:       lint warns about perfectly good casts
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 02 04:15:00 +0000 2010
>Originator:     David A. Holland
>Release:        NetBSD 5.99.22 (20091208, also 20100307)
System: NetBSD tanaqui 5.99.22 NetBSD 5.99.22 (TANAQUI) #31: Tue Dec 8 22:53:35 
EST 2009 dholland@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386

Inspecting the representation of an integer value (or, I suspect, any
other value) with a pointer to unsigned char causes lint to warn that
"pointer casts may be troublesome".


#include <stdio.h>
#include <stdlib.h>

int main() {
   int *p;
   unsigned char *x;
   size_t i;

   p = malloc(sizeof(*p));
   *p = 0x12345678;

   x = (unsigned char *)p;
   for (i=0; i<sizeof(*p); i++) {
      (void)printf(" %02x\n", x[i]);

   return 0;

Use lint -chapbxzFS per It says

foo.c(12): warning: pointer casts may be troublesome [247]

This issue was noticed by agc, but he doesn't think it's important :-)


The problem is in lint1/tree.c at line 1974, which seems to be a
general-purpose test for casting pointers that point to things of
different sizes.

Since inspecting the representation with unsigned char * is the
recommended method of doing various things in standard C the test
there ought to shut up about casts to unsigned (or signed) char.

In the meantime, adding an extra cast through void * makes lint shut
up. (Although I don't immediately see why, which is why I'm not going
to propose a patch for the time being...)

Home | Main Index | Thread Index | Old Index