[Gmp-commit] /home/hgfiles/gmp: Make all bases either work or return an error.

mercurial at gmplib.org mercurial at gmplib.org
Mon Nov 22 22:03:42 CET 2010


details:   /home/hgfiles/gmp/rev/e0b02c0e4e33
changeset: 13692:e0b02c0e4e33
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Nov 22 22:03:28 2010 +0100
description:
Make all bases either work or return an error.

diffstat:

 ChangeLog     |  7 +++++++
 mpf/get_str.c |  6 +++++-
 mpq/get_str.c |  4 ++--
 mpz/get_str.c |  6 +++++-
 mpz/out_str.c |  6 +++++-
 5 files changed, 24 insertions(+), 5 deletions(-)

diffs (97 lines):

diff -r 0e1e5b8d4178 -r e0b02c0e4e33 ChangeLog
--- a/ChangeLog	Sun Nov 14 15:37:59 2010 +0100
+++ b/ChangeLog	Mon Nov 22 22:03:28 2010 +0100
@@ -1,3 +1,10 @@
+2010-11-22  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpz/get_str.c: Make all bases either work or return an error.
+	* mpz/out_str.c: Likewise.
+	* mpq/get_str.c: Likewise.
+	* mpf/get_str.c: Likewise.
+
 2010-11-14  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tests/misc/t-printf.c: Add explicit casts for type conversions.
diff -r 0e1e5b8d4178 -r e0b02c0e4e33 mpf/get_str.c
--- a/mpf/get_str.c	Sun Nov 14 15:37:59 2010 +0100
+++ b/mpf/get_str.c	Mon Nov 22 22:03:28 2010 +0100
@@ -131,7 +131,7 @@
   if (base >= 0)
     {
       num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
-      if (base == 0)
+      if (base <= 1)
 	base = 10;
       else if (base > 36)
 	{
@@ -143,6 +143,10 @@
   else
     {
       base = -base;
+      if (base <= 1)
+        base = 10;
+      else if (base > 36)
+        return NULL;
       num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     }
 
diff -r 0e1e5b8d4178 -r e0b02c0e4e33 mpq/get_str.c
--- a/mpq/get_str.c	Sun Nov 14 15:37:59 2010 +0100
+++ b/mpq/get_str.c	Mon Nov 22 22:03:28 2010 +0100
@@ -27,8 +27,8 @@
 {
   size_t  str_alloc, len;
 
-  ASSERT (ABS(base) >= 2);
-  ASSERT (ABS(base) <= 62);
+  if (base > 62 || base < -36)
+    return NULL;
 
   str_alloc = 0;
   if (str == NULL)
diff -r 0e1e5b8d4178 -r e0b02c0e4e33 mpz/get_str.c
--- a/mpz/get_str.c	Sun Nov 14 15:37:59 2010 +0100
+++ b/mpz/get_str.c	Mon Nov 22 22:03:28 2010 +0100
@@ -43,7 +43,7 @@
   if (base >= 0)
     {
       num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
-      if (base == 0)
+      if (base <= 1)
 	base = 10;
       else if (base > 36)
 	{
@@ -55,6 +55,10 @@
   else
     {
       base = -base;
+      if (base <= 1)
+        base = 10;
+      else if (base > 36)
+        return NULL;
       num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     }
 
diff -r 0e1e5b8d4178 -r e0b02c0e4e33 mpz/out_str.c
--- a/mpz/out_str.c	Sun Nov 14 15:37:59 2010 +0100
+++ b/mpz/out_str.c	Mon Nov 22 22:03:28 2010 +0100
@@ -40,7 +40,7 @@
   if (base >= 0)
     {
       num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
-      if (base == 0)
+      if (base <= 1)
 	base = 10;
       else if (base > 36)
 	{
@@ -52,6 +52,10 @@
   else
     {
       base = -base;
+      if (base <= 1)
+        base = 10;
+      else if (base > 36)
+        return 0;
       num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     }
 


More information about the gmp-commit mailing list