Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen Use strtol() to check validity of numeric value...



details:   https://anonhg.NetBSD.org/src/rev/204912d9ada3
branches:  trunk
changeset: 480790:204912d9ada3
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Thu Jan 20 02:53:46 2000 +0000

description:
Use strtol() to check validity of numeric values, rather than
hand-coding it.

diffstat:

 lib/libc/gen/setmode.c |  15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diffs (46 lines):

diff -r 41953afc8ff6 -r 204912d9ada3 lib/libc/gen/setmode.c
--- a/lib/libc/gen/setmode.c    Thu Jan 20 02:50:54 2000 +0000
+++ b/lib/libc/gen/setmode.c    Thu Jan 20 02:53:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setmode.c,v 1.23 1999/09/20 04:39:05 lukem Exp $       */
+/*     $NetBSD: setmode.c,v 1.24 2000/01/20 02:53:46 mycroft Exp $     */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)setmode.c  8.2 (Berkeley) 3/25/94";
 #else
-__RCSID("$NetBSD: setmode.c,v 1.23 1999/09/20 04:39:05 lukem Exp $");
+__RCSID("$NetBSD: setmode.c,v 1.24 2000/01/20 02:53:46 mycroft Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -184,7 +184,7 @@
        const char *p;
 {
        int perm, who;
-       char op;
+       char op, *ep;
        BITCMD *set, *saveset, *endset;
        sigset_t sigset, sigoset;
        mode_t mask;
@@ -218,16 +218,11 @@
         * or illegal bits.
         */
        if (isdigit((unsigned char)*p)) {
-               perm = (mode_t)strtol(p, NULL, 8);
-               if (perm & ~(STANDARD_BITS|S_ISTXT)) {
+               perm = (mode_t)strtol(p, &ep, 8);
+               if (*ep || perm & ~(STANDARD_BITS|S_ISTXT)) {
                        free(saveset);
                        return (NULL);
                }
-               while (*++p)
-                       if (*p < '0' || *p > '7') {
-                               free(saveset);
-                               return (NULL);
-                       }
                ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
                set->cmd = 0;
                return (saveset);



Home | Main Index | Thread Index | Old Index