[PATCH 2/3] lib/replace: Make sure that replacement strto[u]ll does not reset errno unexpectedly

Felix Janda felix.janda at posteo.de
Mon Jun 22 12:57:23 MDT 2015


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.

Signed-off-by: Felix Janda <felix.janda at posteo.de>
---
 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 2421f97..c447c81 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -520,6 +520,7 @@ long long int rep_strtoll(const char *str, char **endptr, int base)
 #ifdef HAVE_BSD_STRTOLL
 long long int rep_strtoll(const char *str, char **endptr, int base)
 {
+	int errnoo = errno;
 	long long int nb = strtoll(str, endptr, base);
 	/* With glibc EINVAL is only returned if base is not ok */
 	if (errno == EINVAL) {
@@ -528,7 +529,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 = errnoo;
 		}
 	}
 	return nb;
@@ -554,6 +555,7 @@ unsigned long long int rep_strtoull(const char *str, char **endptr, int base)
 #ifdef HAVE_BSD_STRTOLL
 unsigned long long int rep_strtoull(const char *str, char **endptr, int base)
 {
+	int errnoo = errno;
 	unsigned long long int nb = strtoull(str, endptr, base);
 	/* With glibc EINVAL is only returned if base is not ok */
 	if (errno == EINVAL) {
@@ -562,7 +564,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 = errnoo;
 		}
 	}
 	return nb;
-- 
2.3.6



More information about the samba-technical mailing list