Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc Casts and type changes to fix portability is...
details: https://anonhg.NetBSD.org/src/rev/ca70ec38f0aa
branches: trunk
changeset: 777923:ca70ec38f0aa
user: christos <christos%NetBSD.org@localhost>
date: Fri Mar 09 15:41:16 2012 +0000
description:
Casts and type changes to fix portability issues.
- int -> size_t
- adjust width of RHS of shift
- adjust widths of types
diffstat:
common/lib/libc/inet/inet_addr.c | 7 ++++---
common/lib/libc/quad/ashldi3.c | 6 +++---
common/lib/libc/quad/ashrdi3.c | 6 +++---
common/lib/libc/quad/lshrdi3.c | 6 +++---
common/lib/libc/quad/qdivrem.c | 12 ++++++------
common/lib/libc/quad/quad.h | 6 +++---
common/lib/libc/stdlib/_strtol.h | 4 ++--
common/lib/libc/stdlib/_strtoul.h | 4 ++--
common/lib/libc/string/bcmp.c | 6 +++---
common/lib/libc/string/popcount64.c | 14 ++++++++------
common/lib/libc/sys/cpuset.c | 13 +++++++------
11 files changed, 44 insertions(+), 40 deletions(-)
diffs (truncated from 329 to 300 lines):
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/inet/inet_addr.c
--- a/common/lib/libc/inet/inet_addr.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/inet/inet_addr.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inet_addr.c,v 1.2 2008/02/16 17:37:13 apb Exp $ */
+/* $NetBSD: inet_addr.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */
/*
* Copyright (c) 1983, 1990, 1993
@@ -77,7 +77,7 @@
static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
static const char rcsid[] = "Id: inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp";
#else
-__RCSID("$NetBSD: inet_addr.c,v 1.2 2008/02/16 17:37:13 apb Exp $");
+__RCSID("$NetBSD: inet_addr.c,v 1.3 2012/03/09 15:41:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -125,7 +125,8 @@
int
inet_aton(const char *cp, struct in_addr *addr) {
uint32_t val;
- int base, n;
+ int base;
+ size_t n;
char c;
uint8_t parts[4];
uint8_t *pp = parts;
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/quad/ashldi3.c
--- a/common/lib/libc/quad/ashldi3.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/quad/ashldi3.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ashldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */
+/* $NetBSD: ashldi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ashldi3.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: ashldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $");
+__RCSID("$NetBSD: ashldi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -57,7 +57,7 @@
return(a);
aa.q = a;
if (shift >= INT_BITS) {
- aa.ul[H] = aa.ul[L] << (shift - INT_BITS);
+ aa.ul[H] = aa.ul[L] << (unsigned int)(shift - INT_BITS);
aa.ul[L] = 0;
} else {
aa.ul[H] = (aa.ul[H] << shift) |
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/quad/ashrdi3.c
--- a/common/lib/libc/quad/ashrdi3.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/quad/ashrdi3.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ashrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */
+/* $NetBSD: ashrdi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ashrdi3.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: ashrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $");
+__RCSID("$NetBSD: ashrdi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -72,7 +72,7 @@
aa.ul[H] = s;
} else {
aa.ul[L] = (aa.ul[L] >> shift) |
- (aa.ul[H] << (INT_BITS - shift));
+ (aa.ul[H] << (unsigned int)(INT_BITS - shift));
/* LINTED inherits machine dependency */
aa.sl[H] >>= shift;
}
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/quad/lshrdi3.c
--- a/common/lib/libc/quad/lshrdi3.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/quad/lshrdi3.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lshrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */
+/* $NetBSD: lshrdi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)lshrdi3.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: lshrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $");
+__RCSID("$NetBSD: lshrdi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -60,7 +60,7 @@
aa.ul[H] = 0;
} else {
aa.ul[L] = (aa.ul[L] >> shift) |
- (aa.ul[H] << (INT_BITS - shift));
+ (aa.ul[H] << (unsigned int)(INT_BITS - shift));
aa.ul[H] >>= shift;
}
return (aa.q);
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/quad/qdivrem.c
--- a/common/lib/libc/quad/qdivrem.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/quad/qdivrem.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: qdivrem.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */
+/* $NetBSD: qdivrem.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)qdivrem.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: qdivrem.c,v 1.2 2009/03/15 22:31:12 cegger Exp $");
+__RCSID("$NetBSD: qdivrem.c,v 1.3 2012/03/09 15:41:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -49,10 +49,10 @@
#include "quad.h"
-#define B ((int)1 << HALF_BITS) /* digit base */
+#define B ((int)1 << (unsigned int)HALF_BITS) /* digit base */
/* Combine two `digits' to make a single two-digit number. */
-#define COMBINE(a, b) (((u_int)(a) << HALF_BITS) | (b))
+#define COMBINE(a, b) (((u_int)(a) << (unsigned int)HALF_BITS) | (b))
/* select a type for digits in base B: use unsigned short if they fit */
#if UINT_MAX == 0xffffffffU && USHRT_MAX >= 0xffff
@@ -173,7 +173,7 @@
* D1: choose multiplier 1 << d to ensure v[1] >= B/2.
*/
d = 0;
- for (t = v[1]; t < B / 2; t <<= 1)
+ for (t = v[1]; t < B / 2; t <<= (unsigned int)1)
d++;
if (d > 0) {
shl(&u[0], m + n, d); /* u <<= d */
@@ -254,7 +254,7 @@
if (d) {
for (i = m + n; i > m; --i)
u[i] = (digit)(((u_int)u[i] >> d) |
- LHALF((u_int)u[i - 1] << (HALF_BITS - d)));
+ LHALF((u_int)u[i - 1] << (unsigned int)(HALF_BITS - d)));
u[i] = 0;
}
tmp.ul[H] = COMBINE(uspace[1], uspace[2]);
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/quad/quad.h
--- a/common/lib/libc/quad/quad.h Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/quad/quad.h Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quad.h,v 1.4 2011/07/09 02:36:01 matt Exp $ */
+/* $NetBSD: quad.h,v 1.5 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -94,8 +94,8 @@
* (sizeof(int)*CHAR_BIT/2).
*/
#define HHALF(x) ((u_int)(x) >> HALF_BITS)
-#define LHALF(x) ((u_int)(x) & (((int)1 << HALF_BITS) - 1))
-#define LHUP(x) ((u_int)(x) << HALF_BITS)
+#define LHALF(x) ((u_int)(x) & (((int)1 << (u_int)HALF_BITS) - 1))
+#define LHUP(x) ((u_int)(x) << (u_int)HALF_BITS)
/*
* XXX
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/stdlib/_strtol.h
--- a/common/lib/libc/stdlib/_strtol.h Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/stdlib/_strtol.h Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtol.h,v 1.2 2009/05/20 22:03:29 christos Exp $ */
+/* $NetBSD: _strtol.h,v 1.3 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -109,7 +109,7 @@
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
- cutoff = (neg ? __INT_MIN : __INT_MAX);
+ cutoff = (__INT)(neg ? __INT_MIN : __INT_MAX);
cutlim = (int)(cutoff % base);
cutoff /= base;
if (neg) {
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/stdlib/_strtoul.h
--- a/common/lib/libc/stdlib/_strtoul.h Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/stdlib/_strtoul.h Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtoul.h,v 1.1 2008/08/20 12:42:26 joerg Exp $ */
+/* $NetBSD: _strtoul.h,v 1.2 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -91,7 +91,7 @@
/*
* See strtol for comments as to the logic used.
*/
- cutoff = __UINT_MAX / (__UINT)base;
+ cutoff = (__UINT)(__UINT_MAX / (__UINT)base);
cutlim = (int)(__UINT_MAX % (__UINT)base);
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c))
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/string/bcmp.c
--- a/common/lib/libc/string/bcmp.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/string/bcmp.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmp.c,v 1.6 2009/04/25 12:20:48 skrll Exp $ */
+/* $NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: bcmp.c,v 1.6 2009/04/25 12:20:48 skrll Exp $");
+__RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -66,5 +66,5 @@
if (*p1++ != *p2++)
break;
while (--length);
- return(length);
+ return length != 0;
}
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/string/popcount64.c
--- a/common/lib/libc/string/popcount64.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/string/popcount64.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: popcount64.c,v 1.6 2011/08/21 21:25:04 dholland Exp $ */
+/* $NetBSD: popcount64.c,v 1.7 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: popcount64.c,v 1.6 2011/08/21 21:25:04 dholland Exp $");
+__RCSID("$NetBSD: popcount64.c,v 1.7 2012/03/09 15:41:16 christos Exp $");
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <limits.h>
@@ -64,10 +64,12 @@
{
unsigned int c;
- v = v - ((v >> 1) & 0x5555555555555555ULL);
- v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
- v = ((v + (v >> 4)) & 0x0f0f0f0f0f0f0f0fULL) * 0x0101010101010101ULL;
- c = v >> 56;
+ v = v - ((v >> 1) & (uint64_t)0x5555555555555555ULL);
+ v = (v & (uint64_t)0x3333333333333333ULL) +
+ ((v >> 2) & (uint64_t)0x3333333333333333ULL);
+ v = ((v + (v >> 4)) & (uint64_t)0x0f0f0f0f0f0f0f0fULL) *
+ (uint64_t)0x0101010101010101ULL;
+ c = (unsigned int)(v >> 56);
return c;
}
diff -r d13d734ba8e0 -r ca70ec38f0aa common/lib/libc/sys/cpuset.c
--- a/common/lib/libc/sys/cpuset.c Fri Mar 09 15:38:03 2012 +0000
+++ b/common/lib/libc/sys/cpuset.c Fri Mar 09 15:41:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuset.c,v 1.17 2011/08/07 13:33:02 rmind Exp $ */
+/* $NetBSD: cpuset.c,v 1.18 2012/03/09 15:41:16 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#ifndef _STANDALONE
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: cpuset.c,v 1.17 2011/08/07 13:33:02 rmind Exp $");
+__RCSID("$NetBSD: cpuset.c,v 1.18 2012/03/09 15:41:16 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -93,7 +93,7 @@
errno = EINVAL;
return -1;
}
- return ((1 << (i & CPUSET_MASK)) & c->bits[j]) != 0;
+ return ((1 << (unsigned int)(i & CPUSET_MASK)) & c->bits[j]) != 0;
}
Home |
Main Index |
Thread Index |
Old Index