summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorSwen Schillig <swen@linux.ibm.com>2019-06-04 08:57:03 +0200
committerRalph Boehme <slow@samba.org>2019-06-30 11:32:18 +0000
commita8bbd60fd9d10afa0aaf9359782428b8836a9732 (patch)
tree2b13141739710b4d2c2d1e1e25f43b87535fc23b /lib/util
parent73640b8ad8ced213d4855a2698df0d15318696ac (diff)
downloadsamba-a8bbd60fd9d10afa0aaf9359782428b8836a9732.tar.gz
lib: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/access.c9
-rw-r--r--lib/util/asn1.c6
-rw-r--r--lib/util/tests/util.c72
-rw-r--r--lib/util/util_str.c7
4 files changed, 48 insertions, 46 deletions
diff --git a/lib/util/access.c b/lib/util/access.c
index 960fe4b066c..10a14771899 100644
--- a/lib/util/access.c
+++ b/lib/util/access.c
@@ -70,12 +70,15 @@ static bool masked_match(const char *tok, const char *slash, const char *s)
return false;
}
} else {
- char *endp = NULL;
int error = 0;
unsigned long val;
- val = strtoul_err(slash+1, &endp, 0, &error);
- if (error != 0 || *endp != '\0') {
+ val = smb_strtoul(slash+1,
+ NULL,
+ 0,
+ &error,
+ SMB_STR_FULL_STR_CONV);
+ if (error != 0) {
return false;
}
if (!make_netmask(&ss_mask, &ss_tok, val)) {
diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index 70ff5f0ad88..51da5424956 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -278,14 +278,14 @@ bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
int error = 0;
if (!isdigit(*p)) return false;
- v = strtoul_err(p, &newp, 10, &error);
+ v = smb_strtoul(p, &newp, 10, &error, SMB_STR_STANDARD);
if (newp[0] != '.' || error != 0) {
return false;
}
p = newp + 1;
if (!isdigit(*p)) return false;
- v2 = strtoul_err(p, &newp, 10, &error);
+ v2 = smb_strtoul(p, &newp, 10, &error, SMB_STR_STANDARD);
if (newp[0] != '.' || error != 0) {
return false;
}
@@ -300,7 +300,7 @@ bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
i = 1;
while (*p) {
if (!isdigit(*p)) return false;
- v = strtoul_err(p, &newp, 10, &error);
+ v = smb_strtoul(p, &newp, 10, &error, SMB_STR_STANDARD);
if (newp[0] == '.' || error != 0) {
p = newp + 1;
/* check for empty last component */
diff --git a/lib/util/tests/util.c b/lib/util/tests/util.c
index de9dca1ffc5..854d1d2023f 100644
--- a/lib/util/tests/util.c
+++ b/lib/util/tests/util.c
@@ -422,32 +422,32 @@ done:
return ret;
}
-static bool test_strtoul_err_errno_check(struct torture_context *tctx)
+static bool test_smb_strtoul_errno_check(struct torture_context *tctx)
{
const char *number = "123";
unsigned long int val = 0;
unsigned long long int vall = 0;
int err;
- /* select an error code which is not set by the strtoul_err routines */
+ /* select an error code which is not set by the smb_strtoul routines */
errno = EAGAIN;
err = EAGAIN;
- val = strtoul_err(number, NULL, 0, &err);
- torture_assert(tctx, errno == EAGAIN, "strtoul_err: Expected EAGAIN");
- torture_assert(tctx, err == 0, "strtoul_err: Expected err = 0");
- torture_assert(tctx, val == 123, "strtoul_err: Expected value 123");
+ val = smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, errno == EAGAIN, "smb_strtoul: Expected EAGAIN");
+ torture_assert(tctx, err == 0, "smb_strtoul: Expected err = 0");
+ torture_assert(tctx, val == 123, "smb_strtoul: Expected value 123");
/* set err to an impossible value again before continuing */
err = EAGAIN;
- vall = strtoull_err(number, NULL, 0, &err);
- torture_assert(tctx, errno == EAGAIN, "strtoull_err: Expected EAGAIN");
- torture_assert(tctx, err == 0, "strtoul_err: Expected err = 0");
- torture_assert(tctx, vall == 123, "strtoul_err: Expected value 123");
+ vall = smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, errno == EAGAIN, "smb_strtoull: Expected EAGAIN");
+ torture_assert(tctx, err == 0, "smb_strtoul: Expected err = 0");
+ torture_assert(tctx, vall == 123, "smb_strtoul: Expected value 123");
return true;
}
-static bool test_strtoul_err_negative(struct torture_context *tctx)
+static bool test_smb_strtoul_negative(struct torture_context *tctx)
{
const char *number = "-132";
const char *number2 = "132-";
@@ -456,12 +456,12 @@ static bool test_strtoul_err_negative(struct torture_context *tctx)
int err;
err = 0;
- strtoul_err(number, NULL, 0, &err);
- torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
+ smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
err = 0;
- strtoull_err(number, NULL, 0, &err);
- torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
+ smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
/* it is allowed to have a "-" sign after a number,
* e.g. as part of a formular, however, it is not supposed to
@@ -469,39 +469,39 @@ static bool test_strtoul_err_negative(struct torture_context *tctx)
*/
err = 0;
- val = strtoul_err(number2, NULL, 0, &err);
- torture_assert(tctx, err == 0, "strtoul_err: Expected no error");
- torture_assert(tctx, val == 132, "strtoul_err: Wrong value");
+ val = smb_strtoul(number2, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == 0, "smb_strtoul: Expected no error");
+ torture_assert(tctx, val == 132, "smb_strtoul: Wrong value");
err = 0;
- vall = strtoull_err(number2, NULL, 0, &err);
- torture_assert(tctx, err == 0, "strtoull_err: Expected no error");
- torture_assert(tctx, vall == 132, "strtoull_err: Wrong value");
+ vall = smb_strtoull(number2, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == 0, "smb_strtoull: Expected no error");
+ torture_assert(tctx, vall == 132, "smb_strtoull: Wrong value");
return true;
}
-static bool test_strtoul_err_no_number(struct torture_context *tctx)
+static bool test_smb_strtoul_no_number(struct torture_context *tctx)
{
const char *number = "ghijk";
const char *blank = "";
int err;
err = 0;
- strtoul_err(number, NULL, 0, &err);
- torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
+ smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
err = 0;
- strtoull_err(number, NULL, 0, &err);
- torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
+ smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
err = 0;
- strtoul_err(blank, NULL, 0, &err);
- torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
+ smb_strtoul(blank, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
err = 0;
- strtoull_err(blank, NULL, 0, &err);
- torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
+ smb_strtoull(blank, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
return true;
}
@@ -518,13 +518,13 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx)
"directory_create_or_exist",
test_directory_create_or_exist);
torture_suite_add_simple_test(suite,
- "strtoul(l)_err errno",
- test_strtoul_err_errno_check);
+ "smb_strtoul(l) errno",
+ test_smb_strtoul_errno_check);
torture_suite_add_simple_test(suite,
- "strtoul(l)_err negative",
- test_strtoul_err_negative);
+ "smb_strtoul(l) negative",
+ test_smb_strtoul_negative);
torture_suite_add_simple_test(suite,
- "strtoul(l)_err no number",
- test_strtoul_err_no_number);
+ "smb_strtoul(l) no number",
+ test_smb_strtoul_no_number);
return suite;
}
diff --git a/lib/util/util_str.c b/lib/util/util_str.c
index 29a44836bde..3356df34f04 100644
--- a/lib/util/util_str.c
+++ b/lib/util/util_str.c
@@ -69,7 +69,7 @@ _PUBLIC_ bool conv_str_size_error(const char * str, uint64_t * val)
return false;
}
- lval = strtoull_err(str, &end, 10, &error);
+ lval = smb_strtoull(str, &end, 10, &error, SMB_STR_STANDARD);
if (error != 0) {
return false;
}
@@ -103,7 +103,6 @@ _PUBLIC_ bool conv_str_size_error(const char * str, uint64_t * val)
*/
_PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val)
{
- char * end = NULL;
unsigned long long lval;
int error = 0;
@@ -111,8 +110,8 @@ _PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val)
return false;
}
- lval = strtoull_err(str, &end, 10, &error);
- if (error != 0 || *end != '\0') {
+ lval = smb_strtoull(str, NULL, 10, &error, SMB_STR_FULL_STR_CONV);
+ if (error != 0) {
return false;
}