patches/mpfr/2.4.0/110-mpfr_snprintf.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Apr 26 10:47:00 2009 +0000 (2009-04-26)
branch1.4
changeset 1307 39b1c755f19b
permissions -rw-r--r--
1.4: update version to 1.4.0.

-------- diffstat follows --------
/branches/1.4/.version | 2 1 1 0 +-
1 file changed, 1 insertion(+), 1 deletion(-)
yann@1249
     1
diff -Naurd mpfr-2.4.0-a/PATCHES mpfr-2.4.0-b/PATCHES
yann@1249
     2
--- mpfr-2.4.0-a/PATCHES	2009-02-25 13:27:38.000000000 +0000
yann@1249
     3
+++ mpfr-2.4.0-b/PATCHES	2009-02-25 13:42:26.000000000 +0000
yann@1249
     4
@@ -0,0 +1 @@
yann@1249
     5
+mpfr_snprintf
yann@1249
     6
diff -Naurd mpfr-2.4.0-a/VERSION mpfr-2.4.0-b/VERSION
yann@1249
     7
--- mpfr-2.4.0-a/VERSION	2009-02-20 17:27:44.000000000 +0000
yann@1249
     8
+++ mpfr-2.4.0-b/VERSION	2009-02-25 13:41:31.000000000 +0000
yann@1249
     9
@@ -1 +1 @@
yann@1249
    10
-2.4.0-p1
yann@1249
    11
+2.4.0-p2
yann@1249
    12
diff -Naurd mpfr-2.4.0-a/mpfr.h mpfr-2.4.0-b/mpfr.h
yann@1249
    13
--- mpfr-2.4.0-a/mpfr.h	2009-02-20 17:27:44.000000000 +0000
yann@1249
    14
+++ mpfr-2.4.0-b/mpfr.h	2009-02-25 13:41:31.000000000 +0000
yann@1249
    15
@@ -27,7 +27,7 @@
yann@1249
    16
 #define MPFR_VERSION_MAJOR 2
yann@1249
    17
 #define MPFR_VERSION_MINOR 4
yann@1249
    18
 #define MPFR_VERSION_PATCHLEVEL 0
yann@1249
    19
-#define MPFR_VERSION_STRING "2.4.0-p1"
yann@1249
    20
+#define MPFR_VERSION_STRING "2.4.0-p2"
yann@1249
    21
 
yann@1249
    22
 /* Macros dealing with MPFR VERSION */
yann@1249
    23
 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
yann@1249
    24
diff -Naurd mpfr-2.4.0-a/printf.c mpfr-2.4.0-b/printf.c
yann@1249
    25
--- mpfr-2.4.0-a/printf.c	2009-01-26 12:52:01.000000000 +0000
yann@1249
    26
+++ mpfr-2.4.0-b/printf.c	2009-02-25 13:41:22.000000000 +0000
yann@1249
    27
@@ -154,16 +154,16 @@
yann@1249
    28
   int ret;
yann@1249
    29
   size_t min_size;
yann@1249
    30
 
yann@1249
    31
-  /* C99 allows SIZE to be null */
yann@1249
    32
-  if (size == 0)
yann@1249
    33
-    return 0;
yann@1249
    34
-
yann@1249
    35
-  MPFR_ASSERTD (buf != NULL);
yann@1249
    36
-
yann@1249
    37
   GET_STR (ret, str, fmt);
yann@1249
    38
-  min_size = (size_t)ret < size ? (size_t)ret : size - 1;
yann@1249
    39
-  strncpy (buf, str, min_size);
yann@1249
    40
-  buf[min_size + 1] = '\0';
yann@1249
    41
+
yann@1249
    42
+  /* C99 allows SIZE to be zero */
yann@1249
    43
+  if (size != 0)
yann@1249
    44
+    {
yann@1249
    45
+      MPFR_ASSERTN (buf != NULL);
yann@1249
    46
+      min_size = (size_t)ret < size ? (size_t)ret : size - 1;
yann@1249
    47
+      strncpy (buf, str, min_size);
yann@1249
    48
+      buf[min_size] = '\0';
yann@1249
    49
+    }
yann@1249
    50
 
yann@1249
    51
   mpfr_free_str (str);
yann@1249
    52
   return ret;
yann@1249
    53
@@ -176,16 +176,17 @@
yann@1249
    54
   int ret;
yann@1249
    55
   int min_size;
yann@1249
    56
 
yann@1249
    57
-  /* C99 allows SIZE to be null */
yann@1249
    58
-  if (size == 0)
yann@1249
    59
-    return 0;
yann@1249
    60
+  GET_STR_VA (ret, str, fmt, ap);
yann@1249
    61
 
yann@1249
    62
-  MPFR_ASSERTD (buf != NULL);
yann@1249
    63
+  /* C99 allows SIZE to be zero */
yann@1249
    64
+  if (size != 0)
yann@1249
    65
+    {
yann@1249
    66
+      MPFR_ASSERTN (buf != NULL);
yann@1249
    67
+      min_size = (size_t)ret < size ? (size_t)ret : size - 1;
yann@1249
    68
+      strncpy (buf, str, min_size);
yann@1249
    69
+      buf[min_size] = '\0';
yann@1249
    70
+    }
yann@1249
    71
 
yann@1249
    72
-  GET_STR_VA (ret, str, fmt, ap);
yann@1249
    73
-  min_size = (size_t)ret < size ? (size_t)ret : size - 1;
yann@1249
    74
-  strncpy (buf, str, min_size);
yann@1249
    75
-  buf[min_size + 1] = '\0';
yann@1249
    76
   mpfr_free_str (str);
yann@1249
    77
   return ret;
yann@1249
    78
 }
yann@1249
    79
diff -Naurd mpfr-2.4.0-a/tests/tsprintf.c mpfr-2.4.0-b/tests/tsprintf.c
yann@1249
    80
--- mpfr-2.4.0-a/tests/tsprintf.c	2009-01-26 12:52:00.000000000 +0000
yann@1249
    81
+++ mpfr-2.4.0-b/tests/tsprintf.c	2009-02-25 13:41:22.000000000 +0000
yann@1249
    82
@@ -72,21 +72,37 @@
yann@1249
    83
 
yann@1249
    84
   /* test mpfr_snprintf */
yann@1249
    85
   p = (int) (randlimb () % n0);
yann@1249
    86
-  n1 = mpfr_snprintf (buffer, p, fmt, x);
yann@1249
    87
-  if ((p != 0 && n0 != n1) || (p == 0 && n1 != 0))
yann@1249
    88
+  if (p == 0 && (randlimb () & 1) == 0)
yann@1249
    89
+    {
yann@1249
    90
+      n1 = mpfr_snprintf (NULL, 0, fmt, x);
yann@1249
    91
+    }
yann@1249
    92
+  else
yann@1249
    93
+    {
yann@1249
    94
+      buffer[p] = 17;
yann@1249
    95
+      n1 = mpfr_snprintf (buffer, p, fmt, x);
yann@1249
    96
+      if (buffer[p] != 17)
yann@1249
    97
+        {
yann@1249
    98
+          printf ("Buffer overflow in mpfr_snprintf for p = %d!\n", p);
yann@1249
    99
+          exit (1);
yann@1249
   100
+        }
yann@1249
   101
+    }
yann@1249
   102
+  if (n0 != n1)
yann@1249
   103
     {
yann@1249
   104
       printf ("Error in mpfr_snprintf (s, %d, \"%s\", x) return value\n",
yann@1249
   105
               p, fmt);
yann@1249
   106
       printf ("expected: %d\ngot:      %d\n", n0, n1);
yann@1249
   107
       exit (1);
yann@1249
   108
     }
yann@1249
   109
-  if (strncmp (expected, buffer, p) != 0)
yann@1249
   110
+  if ((p > 1 && strncmp (expected, buffer, p-1) != 0)
yann@1249
   111
+      || (p == 1 && buffer[0] != '\0'))
yann@1249
   112
     {
yann@1249
   113
-      printf ("Error in mpfr_snprintf (s, %d, \"%s\", x);\n", p, fmt);
yann@1249
   114
-      printf ("expected: \"%s\"\ngot:      \"%s\"\n", expected, buffer);
yann@1249
   115
+      char part_expected[p];
yann@1249
   116
+      strncpy (part_expected, expected, p);
yann@1249
   117
+      part_expected[p-1] = '\0';
yann@1249
   118
+      printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...);\n", p, fmt);
yann@1249
   119
+      printf ("expected: \"%s\"\ngot:      \"%s\"\n", part_expected, buffer);
yann@1249
   120
       exit (1);
yann@1249
   121
     }
yann@1249
   122
-
yann@1249
   123
   return n0;
yann@1249
   124
 }
yann@1249
   125
 
yann@1249
   126
@@ -116,8 +132,21 @@
yann@1249
   127
 
yann@1249
   128
   /* test mpfr_snprintf */
yann@1249
   129
   p = (int) (randlimb () % n0);
yann@1249
   130
-  n1 = mpfr_vsnprintf (buffer, p, fmt, ap1);
yann@1249
   131
-  if ((p != 0 && n0 != n1) || (p == 0 && n1 != 0))
yann@1249
   132
+  if (p == 0 && (randlimb () & 1) == 0)
yann@1249
   133
+    {
yann@1249
   134
+      n1 = mpfr_vsnprintf (NULL, 0, fmt, ap1);
yann@1249
   135
+    }
yann@1249
   136
+  else
yann@1249
   137
+    {
yann@1249
   138
+      buffer[p] = 17;
yann@1249
   139
+      n1 = mpfr_vsnprintf (buffer, p, fmt, ap1);
yann@1249
   140
+      if (buffer[p] != 17)
yann@1249
   141
+        {
yann@1249
   142
+          printf ("Buffer overflow in mpfr_vsnprintf for p = %d!\n", p);
yann@1249
   143
+          exit (1);
yann@1249
   144
+        }
yann@1249
   145
+    }
yann@1249
   146
+  if (n0 != n1)
yann@1249
   147
     {
yann@1249
   148
       printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...) return value\n",
yann@1249
   149
               p, fmt);
yann@1249
   150
@@ -126,10 +155,14 @@
yann@1249
   151
       va_end (ap1);
yann@1249
   152
       exit (1);
yann@1249
   153
     }
yann@1249
   154
-  if (strncmp (expected, buffer, p) != 0)
yann@1249
   155
+  if ((p > 1 && strncmp (expected, buffer, p-1) != 0)
yann@1249
   156
+      || (p == 1 && buffer[0] != '\0'))
yann@1249
   157
     {
yann@1249
   158
+      char part_expected[p];
yann@1249
   159
+      strncpy (part_expected, expected, p);
yann@1249
   160
+      part_expected[p-1] = '\0';
yann@1249
   161
       printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...);\n", p, fmt);
yann@1249
   162
-      printf ("expected: \"%s\"\ngot:      \"%s\"\n", expected, buffer);
yann@1249
   163
+      printf ("expected: \"%s\"\ngot:      \"%s\"\n", part_expected, buffer);
yann@1249
   164
 
yann@1249
   165
       va_end (ap1);
yann@1249
   166
       exit (1);
yann@1249
   167
diff -Naurd mpfr-2.4.0-a/version.c mpfr-2.4.0-b/version.c
yann@1249
   168
--- mpfr-2.4.0-a/version.c	2009-02-20 17:27:44.000000000 +0000
yann@1249
   169
+++ mpfr-2.4.0-b/version.c	2009-02-25 13:41:31.000000000 +0000
yann@1249
   170
@@ -25,5 +25,5 @@
yann@1249
   171
 const char *
yann@1249
   172
 mpfr_get_version (void)
yann@1249
   173
 {
yann@1249
   174
-  return "2.4.0-p1";
yann@1249
   175
+  return "2.4.0-p2";
yann@1249
   176
 }