]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - pw/strtounum.c
Partially revert r367756 (chpass(1) synopsis changes)
[pw-darwin.git] / pw / strtounum.c
index 8d8347080ac2d1ce329683cd9c7c3859538b14e0..ae578bdeaeba22da613b74e50bda0acc747e3052 100644 (file)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (C) Baptiste Daroussin <bapt@FreeBSD.org>
+ * Copyright (C) 2015 Baptiste Daroussin <bapt@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,30 +41,27 @@ strtounum(const char * __restrict np, uintmax_t minval, uintmax_t maxval,
        char *endp;
        uintmax_t ret;
 
+       *errpp = NULL;
        if (minval > maxval) {
                errno = EINVAL;
-               if (errpp != NULL)
-                       *errpp = "invalid";
+               *errpp = "invalid";
                return (0);
        }
        errno = 0;
        ret = strtoumax(np, &endp, 10);
        if (endp == np || *endp != '\0') {
                errno = EINVAL;
-               if (errpp != NULL)
-                       *errpp = "invalid";
+               *errpp = "invalid";
                return (0);
        }
        if (ret < minval) {
                errno = ERANGE;
-               if (errpp != NULL)
-                       *errpp = "too small";
+               *errpp = "too small";
                return (0);
        }
        if (errno == ERANGE || ret > maxval) {
                errno = ERANGE;
-               if (errpp != NULL)
-                       *errpp = "too large";
+               *errpp = "too large";
                return (0);
        }
        return (ret);