about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-06-15 12:07:01 +0000
committerUlrich Drepper <drepper@redhat.com>1999-06-15 12:07:01 +0000
commit61464e3e737575c2f0df89866a32ff546b066fa1 (patch)
tree4a5f92f880328fd6f01d76d5024f1ba0aabfd467 /sysdeps
parent540009244c7c9f1aec64af6fb1efba7245ed8bb3 (diff)
downloadglibc-61464e3e737575c2f0df89866a32ff546b066fa1.tar.gz
glibc-61464e3e737575c2f0df89866a32ff546b066fa1.tar.xz
glibc-61464e3e737575c2f0df89866a32ff546b066fa1.zip
Update.
1999-06-14  Geoff Keating  <geoffk@ozemail.com.au>

	* stdlib/tst-strtoll.c: New file.
	* stdlib/Makefile (tests): Add tst-strtoll.c
	* stdlib/strtol.c: It is not generally true that if
	(unsigned)a*(unsigned)b overflows, then the result is
	less than 'a'.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/strtol.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sysdeps/generic/strtol.c b/sysdeps/generic/strtol.c
index 6ba2960f29..42da792c44 100644
--- a/sysdeps/generic/strtol.c
+++ b/sysdeps/generic/strtol.c
@@ -348,6 +348,7 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
   if (sizeof (long int) != sizeof (LONG int))
     {
       unsigned long int j = 0;
+      unsigned long int jmax = ULONG_MAX / base;
 
       for (;c != L_('\0'); c = *++s)
 	{
@@ -362,18 +363,14 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
 	  if ((int) c >= base)
 	    break;
 	  /* Note that we never can have an overflow.  */
-	  else
+	  else if (j >= jmax)
 	    {
-	      unsigned long int jj = j * (unsigned long int) base;
-	      if (jj < j)
-		{
-		  /* We have an overflow.  Now use the long representation.  */
-		  i = (unsigned LONG int) j;
-		  goto use_long;
-		}
-	      j = jj;
-	      j += c;
+	      /* We have an overflow.  Now use the long representation.  */
+	      i = (unsigned LONG int) j;
+	      goto use_long;
 	    }
+	  else
+	    j = j * (unsigned long int) base + c;
 	}
 
       i = (unsigned LONG int) j;