Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/chpass Fix warnings found by gcc-current with alpha ...



details:   https://anonhg.NetBSD.org/src/rev/50bac2832f6a
branches:  trunk
changeset: 526705:50bac2832f6a
user:      simonb <simonb%NetBSD.org@localhost>
date:      Thu May 09 01:58:39 2002 +0000

description:
Fix warnings found by gcc-current with alpha target:
There's no use assigning the output of strtoul() to a 32-bit variable
then checking that against ULONG_MAX.  Instead use a "unsigned long"
as the temporary variable.  Also, only check against UID_MAX/GID_MAX;
these are both going to be smaller than ULONG_MAX on both 32- and 64-bit
platforms.

diffstat:

 usr.bin/chpass/field.c |  24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diffs (72 lines):

diff -r e850a64a3b6e -r 50bac2832f6a usr.bin/chpass/field.c
--- a/usr.bin/chpass/field.c    Thu May 09 01:00:12 2002 +0000
+++ b/usr.bin/chpass/field.c    Thu May 09 01:58:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: field.c,v 1.7 1998/08/10 23:21:05 kim Exp $    */
+/*     $NetBSD: field.c,v 1.8 2002/05/09 01:58:39 simonb Exp $ */
 
 /*
  * Copyright (c) 1988, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)field.c    8.4 (Berkeley) 4/2/94";
 #else 
-__RCSID("$NetBSD: field.c,v 1.7 1998/08/10 23:21:05 kim Exp $");
+__RCSID("$NetBSD: field.c,v 1.8 2002/05/09 01:58:39 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -112,7 +112,7 @@
        struct passwd *pw;
        ENTRY *ep;
 {
-       uid_t id;
+       unsigned long id;
        char *np;
 
        if (!*p) {
@@ -125,11 +125,15 @@
        }
        errno = 0;
        id = strtoul(p, &np, 10);
-       if (*np || (id == ULONG_MAX && errno == ERANGE)) {
+       /*
+        * We don't need to check the return value of strtoul()
+        * since ULONG_MAX is greater than UID_MAX.
+        */
+       if (*np || id > UID_MAX) {
                warnx("illegal uid");
                return (1);
        }
-       pw->pw_uid = id;
+       pw->pw_uid = (uid_t)id;
        return (0);
 }
 
@@ -141,7 +145,7 @@
        ENTRY *ep;
 {
        struct group *gr;
-       gid_t id;
+       unsigned long id;
        char *np;
 
        if (!*p) {
@@ -158,11 +162,15 @@
        }
        errno = 0;
        id = strtoul(p, &np, 10);
-       if (*np || (id == ULONG_MAX && errno == ERANGE)) {
+       /*
+        * We don't need to check the return value of strtoul() 
+        * since ULONG_MAX is greater than GID_MAX.
+        */
+       if (*np || id > GID_MAX) {
                warnx("illegal gid");
                return (1);
        }
-       pw->pw_gid = id;
+       pw->pw_gid = (gid_t)id;
        return (0);
 }
 



Home | Main Index | Thread Index | Old Index