utils: Update error check for new string conversion wrapper
authorSwen Schillig <swen@linux.ibm.com>
Wed, 6 Mar 2019 08:29:13 +0000 (09:29 +0100)
committerChristof Schmitt <cs@samba.org>
Thu, 11 Apr 2019 22:29:26 +0000 (22:29 +0000)
The new string conversion wrappers detect and flag errors
which occured during the string to integer conversion.
Those modifications required an update of the callees
error checks.

Signed-off-by: Swen Schillig <swen@linux.ibm.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
source3/utils/net_idmap.c
source3/utils/net_sam.c
source3/utils/pdbedit.c
source3/utils/regedit_dialog.c

index f6c9f3a1a3d4a4cda30c4d9557da31bd9262ff6b..d1a6db95921950955490154465f1abd818a3d9f5 100644 (file)
@@ -631,16 +631,10 @@ static bool parse_uint32(const char *str, uint32_t *result)
        int error = 0;
 
        val = strtoul_err(str, &endptr, 10, &error);
-
-       if (str == endptr) {
-               return false;
-       }
-       if (*endptr != '\0') {
-               return false;
-       }
-       if (error != 0) {
+       if (error != 0 || *endptr != '\0') {
                return false;
        }
+
        *result = val;          /* Potential crop */
        return true;
 }
index fc2a7baacef4cef5b666b9135b1133027264c4ee..164d9408c56f4b9a7d38a8860ea952d54b55f073 100644 (file)
@@ -503,7 +503,7 @@ static int net_sam_policy_set(struct net_context *c, int argc, const char **argv
        else {
                value = strtoul_err(argv[1], &endptr, 10, &err);
 
-               if ((endptr == argv[1]) || (endptr[0] != '\0') || (err != 0)) {
+               if (err != 0 || *endptr != '\0') {
                        d_printf(_("Unable to set policy \"%s\"! Invalid value "
                                 "\"%s\".\n"),
                                 account_policy, argv[1]);
index c80d5411b0026c170379e0d43f2527cfb9efc4d8..462c753217e3206a276b7f7cd817fa16bbf24be4 100644 (file)
@@ -602,10 +602,7 @@ static int set_user_info(const char *username, const char *fullname,
                        uint32_t num;
 
                        num = strtoul_err(kickoff_time, &endptr, 10, &error);
-                       if ((endptr == kickoff_time) ||
-                           (endptr[0] != '\0') ||
-                           (error != 0))
-                       {
+                       if (error != 0 || *endptr != '\0') {
                                fprintf(stderr, "Failed to parse kickoff time\n");
                                return -1;
                        }
index aeea70ac22e5c4e411c0488cd3bdc083e3a131cb..7dd9f0fadea8b7674025d4c3587b9c8b11ccc4c6 100644 (file)
@@ -1029,7 +1029,6 @@ bool dialog_section_text_field_get_int(struct dialog_section *section,
 bool dialog_section_text_field_get_uint(struct dialog_section *section,
                                        unsigned long long *out)
 {
-       bool rv;
        const char *buf;
        char *endp;
        int error = 0;
@@ -1043,12 +1042,11 @@ bool dialog_section_text_field_get_uint(struct dialog_section *section,
                return false;
        }
        *out = strtoull_err(buf, &endp, 0, &error);
-       rv = true;
-       if (endp == buf || endp == NULL || endp[0] != '\0' || error != 0) {
-               rv = false;
+       if (error != 0 || *endp != '\0') {
+               return false;
        }
 
-       return rv;
+       return true;
 }
 
 /* hex editor field */