Subject: lib/36668: bogus complaints about sys/endian.h code when running lint -aa
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <mccratch@gmx.net>
List: netbsd-bugs
Date: 07/20/2007 09:05:00
>Number: 36668
>Category: lib
>Synopsis: bogus complaints about sys/endian.h code when running lint -aa
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Jul 20 09:05:00 +0000 2007
>Originator: Matthias Kretschmer
>Release: 4.0_BETA2
>Organization:
>Environment:
NetBSD tiger 4.0_BETA2 NetBSD 4.0_BETA2 (GENERIC.MP) #4: Tue Jun 5 15:52:40 CEST 2007
>Description:
"lint -aa" complains about "may loose accuracy" for sys/endian.h.
This is no bug at all, just annoying when using lint -aa.
>How-To-Repeat:
$ cat > test.c << EOF
#include <sys/endian.h>
EOF
$ lint -aa test.c
>Fix:
Add explicit typecasts (e.g. applying the following patch to sys/endian.h).
The semantics of the code aren't touched as the compiler has to implicitly cast the values to the given types when running this code.
--- endian.h.orig 2005-02-03 20:16:10.000000000 +0100
+++ endian.h 2007-07-20 10:23:33.000000000 +0200
@@ -190,8 +190,8 @@
{
uint8_t *p = (uint8_t *)buf;
- p[0] = ((unsigned)u >> 8) & 0xff;
- p[1] = u & 0xff;
+ p[0] = (uint8_t)(((unsigned)u >> 8) & 0xff);
+ p[1] = (uint8_t)(u & 0xff);
}
static __inline void __unused
@@ -199,8 +199,8 @@
{
uint8_t *p = (uint8_t *)buf;
- p[0] = u & 0xff;
- p[1] = ((unsigned)u >> 8) & 0xff;
+ p[0] = (uint8_t)(u & 0xff);
+ p[1] = (uint8_t)(((unsigned)u >> 8) & 0xff);
}
static __inline uint16_t __unused
@@ -208,7 +208,7 @@
{
const uint8_t *p = (const uint8_t *)buf;
- return ((p[0] << 8) | p[1]);
+ return (uint16_t)((p[0] << 8) | p[1]);
}
static __inline uint16_t __unused
@@ -216,7 +216,7 @@
{
const uint8_t *p = (const uint8_t *)buf;
- return ((p[1] << 8) | p[0]);
+ return (uint16_t)((p[1] << 8) | p[0]);
}
static __inline void __unused
@@ -224,10 +224,10 @@
{
uint8_t *p = (uint8_t *)buf;
- p[0] = (u >> 24) & 0xff;
- p[1] = (u >> 16) & 0xff;
- p[2] = (u >> 8) & 0xff;
- p[3] = u & 0xff;
+ p[0] = (uint8_t)((u >> 24) & 0xff);
+ p[1] = (uint8_t)((u >> 16) & 0xff);
+ p[2] = (uint8_t)((u >> 8) & 0xff);
+ p[3] = (uint8_t)(u & 0xff);
}
static __inline void __unused
@@ -235,10 +235,10 @@
{
uint8_t *p = (uint8_t *)buf;
- p[0] = u & 0xff;
- p[1] = (u >> 8) & 0xff;
- p[2] = (u >> 16) & 0xff;
- p[3] = (u >> 24) & 0xff;
+ p[0] = (uint8_t)(u & 0xff);
+ p[1] = (uint8_t)((u >> 8) & 0xff);
+ p[2] = (uint8_t)((u >> 16) & 0xff);
+ p[3] = (uint8_t)((u >> 24) & 0xff);
}
static __inline uint32_t __unused