From 89d254ddca20a36001c9dfdcfa6d8b9767f0f897 Mon Sep 17 00:00:00 2001 From: Felix Janda Date: Thu, 22 Oct 2015 12:37:55 +0200 Subject: [PATCH] lib/replace: Make sure that replacement strto[u]ll does not reset errno unexpectedly Fix the replacement functions for strtoll and strtoull to not set errno to 0 if errno is EINVAL before calling, strto[u]ll does not modify errno and the base is ok. Bug: https://bugzilla.samba.org/show_bug.cgi?id=11455 Signed-off-by: Felix Janda Reviewed-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- lib/replace/replace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/replace/replace.c b/lib/replace/replace.c index ce8f38a6e73..b5d7f117857 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -541,6 +541,7 @@ long long int rep_strtoll(const char *str, char **endptr, int base) #undef strtoll long long int rep_strtoll(const char *str, char **endptr, int base) { + int saved_errno = errno; long long int nb = strtoll(str, endptr, base); /* With glibc EINVAL is only returned if base is not ok */ if (errno == EINVAL) { @@ -549,7 +550,7 @@ long long int rep_strtoll(const char *str, char **endptr, int base) * able to make the convertion. * Let's reset errno. */ - errno = 0; + errno = saved_errno; } } return nb; @@ -576,6 +577,7 @@ unsigned long long int rep_strtoull(const char *str, char **endptr, int base) #undef strtoull unsigned long long int rep_strtoull(const char *str, char **endptr, int base) { + int saved_errno = errno; unsigned long long int nb = strtoull(str, endptr, base); /* With glibc EINVAL is only returned if base is not ok */ if (errno == EINVAL) { @@ -584,7 +586,7 @@ unsigned long long int rep_strtoull(const char *str, char **endptr, int base) * able to make the convertion. * Let's reset errno. */ - errno = 0; + errno = saved_errno; } } return nb; -- 2.11.4.GIT