This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch master updated. glibc-2.23-353-gdb1fa6b


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  db1fa6b8d32a0c7155dcaed2f5f9388511613595 (commit)
       via  b26053dd9a0170b58bb01226056e3140b1fb9911 (commit)
       via  dba0832af1eeb0d749aec072ce20f9811fb4b7d6 (commit)
      from  bc779a1a5b3035133024b21e2f339fe4219fb11c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=db1fa6b8d32a0c7155dcaed2f5f9388511613595

commit db1fa6b8d32a0c7155dcaed2f5f9388511613595
Author: Paul E. Murphy <murphyp@linux.vnet.ibm.com>
Date:   Mon May 9 14:20:17 2016 -0500

    Refactor tst-strtod6.c
    
    Use the type-generic macros in tst-strtod.h to simplify this
    test case and enable extension to future variants of this
    functions.

diff --git a/ChangeLog b/ChangeLog
index d756803..14822af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2016-05-23  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
 
+	* stdlib/tst-strtod6.c (do_test): Use new type generic
+	invocation of the test function.
+	(test): Refactor into ...
+	(TEST_STRTOD): New macro base function.
+
+2016-05-23  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
+
 	* stdlib/bug-strtod2.c (do_test): Refactor strtod usage into ...
 	(TEST_STRTOD): New macro.
 	(TEST_FUNCTION): Redefine to use STRTOD_TEST_FOREACH
diff --git a/stdlib/tst-strtod6.c b/stdlib/tst-strtod6.c
index 15e79fd..6b3bb84 100644
--- a/stdlib/tst-strtod6.c
+++ b/stdlib/tst-strtod6.c
@@ -3,83 +3,52 @@
 #include <stdlib.h>
 #include <string.h>
 
-static int
-test (const char str[])
-{
-  char *endp;
-  int result = 0;
-
-  puts (str);
-
-  double d = strtod (str, &endp);
-  if (!isnan (d))
-    {
-      puts ("strtod did not return NAN");
-      result = 1;
-    }
-  if (issignaling (d))
-    {
-      puts ("strtod returned a sNAN");
-      result = 1;
-    }
-  if (strcmp (endp, "something") != 0)
-    {
-      puts  ("strtod set incorrect end pointer");
-      result = 1;
-    }
-
-  float f = strtof (str, &endp);
-  if (!isnanf (f))
-    {
-      puts ("strtof did not return NAN");
-      result = 1;
-    }
-  if (issignaling (f))
-    {
-      puts ("strtof returned a sNAN");
-      result = 1;
-    }
-  if (strcmp (endp, "something") != 0)
-    {
-      puts  ("strtof set incorrect end pointer");
-      result = 1;
-    }
-
-  long double ld = strtold (str, &endp);
-  if (!isnan (ld))
-    {
-      puts ("strtold did not return NAN");
-      result = 1;
-    }
-  if (issignaling (ld))
-    {
-      puts ("strtold returned a sNAN");
-      result = 1;
-    }
-  if (strcmp (endp, "something") != 0)
-    {
-      puts  ("strtold set incorrect end pointer");
-      result = 1;
-    }
-
-  return result;
+#include "tst-strtod.h"
+
+#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
+static int						  \
+test_strto ## FSUF (const char str[])			  \
+{							  \
+  char *endp;						  \
+  int result = 0;					  \
+  puts (str);						  \
+  FTYPE d = strto ## FSUF (str, &endp);			  \
+  if (!isnan (d))					  \
+    {							  \
+      puts ("strto" #FSUF " did not return NAN");	  \
+      result = 1;					  \
+    }							  \
+  if (issignaling (d))					  \
+    {							  \
+      puts ("strto" #FSUF " returned a sNAN");		  \
+      result = 1;					  \
+    }							  \
+  if (strcmp (endp, "something") != 0)			  \
+    {							  \
+      puts ("strto" #FSUF " set incorrect end pointer");  \
+      result = 1;					  \
+    }							  \
+  return result;					  \
 }
 
+GEN_TEST_STRTOD_FOREACH (TEST_STRTOD);
+
 static int
 do_test (void)
 {
   int result = 0;
 
-  result |= test ("NaN(blabla)something");
-  result |= test ("NaN(1234)something");
+  result |= STRTOD_TEST_FOREACH (test_strto, "NaN(blabla)something");
+  result |= STRTOD_TEST_FOREACH (test_strto, "NaN(1234)something");
   /* UINT32_MAX.  */
-  result |= test ("NaN(4294967295)something");
+  result |= STRTOD_TEST_FOREACH (test_strto, "NaN(4294967295)something");
   /* UINT64_MAX.  */
-  result |= test ("NaN(18446744073709551615)something");
+  result |= STRTOD_TEST_FOREACH (test_strto,
+				 "NaN(18446744073709551615)something");
   /* The case of zero is special in that "something" has to be done to make the
      mantissa different from zero, which would mean infinity instead of
      NaN.  */
-  result |= test ("NaN(0)something");
+  result |= STRTOD_TEST_FOREACH (test_strto, "NaN(0)something");
 
   return result;
 }

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=b26053dd9a0170b58bb01226056e3140b1fb9911

commit b26053dd9a0170b58bb01226056e3140b1fb9911
Author: Paul E. Murphy <murphyp@linux.vnet.ibm.com>
Date:   Fri May 6 16:13:29 2016 -0500

    Refactor bug-strtod2.c to be type generic
    
    This only tested for strtod. This expands the testing to
    all variants of strto*.

diff --git a/ChangeLog b/ChangeLog
index de34b56..d756803 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-05-23  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
 
+	* stdlib/bug-strtod2.c (do_test): Refactor strtod usage into ...
+	(TEST_STRTOD): New macro.
+	(TEST_FUNCTION): Redefine to use STRTOD_TEST_FOREACH
+
+2016-05-23  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
+
 	* stdlib/tst-strtod6.c (do_test): Use new type generic
 	invocation of the test function.
 	(test): Refactor into ...
diff --git a/stdlib/bug-strtod2.c b/stdlib/bug-strtod2.c
index a1f037c..cd13e9a 100644
--- a/stdlib/bug-strtod2.c
+++ b/stdlib/bug-strtod2.c
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "tst-strtod.h"
+
 static const char *tests[] =
   {
     "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF",
@@ -10,6 +12,32 @@ static const char *tests[] =
   };
 #define ntests (sizeof (tests) / sizeof (tests[0]))
 
+#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF)		\
+static int								\
+test_strto ## FSUF (void)						\
+{									\
+  int res = 0;								\
+  for (int i = 0; i < ntests; ++i)					\
+    {									\
+      char *endp;							\
+      FTYPE d = strto ## FSUF (tests[i], &endp);			\
+      if (*endp != '\0')						\
+	{								\
+	  printf ("did not consume all of '%s'\n", tests[i]);		\
+	  res = 1;							\
+	}								\
+      if (!isinf (d))							\
+	{								\
+	  printf ("'%s' does not pass isinf\n", tests[i]);		\
+	  res = 1;							\
+	}								\
+    }									\
+									\
+  return res;								\
+}
+
+GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
+
 static int
 do_test (void)
 {
@@ -22,24 +50,7 @@ do_test (void)
       return 0;
     }
 
-  int res = 0;
-  for (int i = 0; i < ntests; ++i)
-    {
-      char *endp;
-      double d = strtod (tests[i], &endp);
-      if (*endp != '\0')
-	{
-	  printf ("did not consume all of '%s'\n", tests[i]);
-	  res = 1;
-	}
-      if (!isinf (d))
-	{
-	  printf ("'%s' does not pass isinf\n", tests[i]);
-	  res = 1;
-	}
-    }
-
-  return res;
+  return STRTOD_TEST_FOREACH (test_strto);
 }
 
 #define TEST_FUNCTION do_test ()

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=dba0832af1eeb0d749aec072ce20f9811fb4b7d6

commit dba0832af1eeb0d749aec072ce20f9811fb4b7d6
Author: Paul E. Murphy <murphyp@linux.vnet.ibm.com>
Date:   Fri May 6 16:00:39 2016 -0500

    Refactor bug-strtod.c to better test new types.
    
    This introduces tst-strtod.h to contain some macros
    to assist with updating strto{f,d,ld} test code to
    support additional variants of this function.

diff --git a/ChangeLog b/ChangeLog
index ab323b2..de34b56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-05-23  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
+
+	* stdlib/tst-strtod6.c (do_test): Use new type generic
+	invocation of the test function.
+	(test): Refactor into ...
+	(TEST_STRTOD): New macro base function.
+
 2016-05-23  Florian Weimer  <fweimer@redhat.com>
 
 	CVE-2016-4429
diff --git a/stdlib/bug-strtod.c b/stdlib/bug-strtod.c
index 82e7d30..c8b56aa 100644
--- a/stdlib/bug-strtod.c
+++ b/stdlib/bug-strtod.c
@@ -21,73 +21,47 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "tst-strtod.h"
+
+#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF)		\
+static int								\
+test_strto ## FSUF (void)						\
+{									\
+  char buf[300];							\
+  int cnt;								\
+  int result = 0;							\
+									\
+  for (cnt = 0; cnt < 200; ++cnt)					\
+    {									\
+      ssize_t n;							\
+      FTYPE f;								\
+									\
+      n = sprintf (buf, "%d", cnt);					\
+      memset (buf + n, '0', cnt);					\
+      sprintf (buf + n + cnt, ".000e-%d", cnt);				\
+      f = strto ## FSUF (buf, NULL);					\
+									\
+      if (f != (FTYPE) cnt)						\
+	{								\
+	  char fstr[FSTRLENMAX];					\
+	  char fcntstr[FSTRLENMAX];					\
+	  FTOSTR (fstr, sizeof (fstr), "%" FTOSTRM "g", f);		\
+	  FTOSTR (fcntstr, sizeof (fstr), "%" FTOSTRM "g", (FTYPE) cnt); \
+	  printf ("strto" #FSUF "(\"%s\") "				\
+		  "failed for cnt == %d (%s instead of %s)\n",		\
+		  buf, cnt, fstr, fcntstr);				\
+	  result = 1;							\
+	}								\
+      else								\
+	printf ( "strto" #FSUF "() fine for cnt == %d\n", cnt);		\
+    }									\
+  return result;							\
+}
+
+GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
 
 int
 main (void)
 {
-  char buf[300];
-  int cnt;
-  int result = 0;
-
-  for (cnt = 0; cnt < 200; ++cnt)
-    {
-      ssize_t n;
-      float f;
-
-      n = sprintf (buf, "%d", cnt);
-      memset (buf + n, '0', cnt);
-      sprintf (buf + n + cnt, ".000e-%d", cnt);
-      f = strtof (buf, NULL);
-
-      if (f != (float) cnt)
-	{
-	  printf ("strtof(\"%s\") failed for cnt == %d (%g instead of %g)\n",
-		  buf, cnt, f, (float) cnt);
-	  result = 1;
-	}
-      else
-	printf ("strtof() fine for cnt == %d\n", cnt);
-    }
-
-  for (cnt = 0; cnt < 200; ++cnt)
-    {
-      ssize_t n;
-      double f;
-
-      n = sprintf (buf, "%d", cnt);
-      memset (buf + n, '0', cnt);
-      sprintf (buf + n + cnt, ".000e-%d", cnt);
-      f = strtod (buf, NULL);
-
-      if (f != (double) cnt)
-	{
-	  printf ("strtod(\"%s\") failed for cnt == %d (%g instead of %g)\n",
-		  buf, cnt, f, (double) cnt);
-	  result = 1;
-	}
-      else
-	printf ("strtod() fine for cnt == %d\n", cnt);
-    }
-
-  for (cnt = 0; cnt < 200; ++cnt)
-    {
-      ssize_t n;
-      long double f;
-
-      n = sprintf (buf, "%d", cnt);
-      memset (buf + n, '0', cnt);
-      sprintf (buf + n + cnt, ".000e-%d", cnt);
-      f = strtold (buf, NULL);
-
-      if (f != (long double) cnt)
-	{
-	  printf ("strtold(\"%s\") failed for cnt == %d (%Lg instead of %Lg)\n",
-		  buf, cnt, f, (long double) cnt);
-	  result = 1;
-	}
-      else
-	printf ("strtold() fine for cnt == %d\n", cnt);
-    }
-
-  return result;
+  return STRTOD_TEST_FOREACH (test_strto);
 }
diff --git a/stdlib/tst-strtod.h b/stdlib/tst-strtod.h
new file mode 100644
index 0000000..d53c1de
--- /dev/null
+++ b/stdlib/tst-strtod.h
@@ -0,0 +1,50 @@
+/* Common utilities for testing strtod and its derivatives.
+   This file is part of the GNU C Library.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _TST_STRTOD_H
+#define _TST_STRTOD_H
+
+#define FSTRLENMAX 128
+
+/* Splat n variants of the same test for the various strtod functions.  */
+#define GEN_TEST_STRTOD_FOREACH(mfunc)		  \
+    mfunc (  f,       float, snprintf,  "", f, f) \
+    mfunc (  d,      double, snprintf,  "",  ,  ) \
+    mfunc ( ld, long double, snprintf, "L", L, l)
+/* The arguments to the generated macros are:
+   FSUF - Function suffix
+   FTYPE - float type
+   FTOSTR - float to string func
+   FTOSTRM - Optional modifier for FTOSTR format
+   LSUF - Literal suffix
+   CSUF - C standardish suffix for many of the math functions
+*/
+
+
+
+#define STRTOD_TEST_FOREACH(mfunc, ...)	  \
+({					  \
+   int result = 0;			  \
+   result |= mfunc ## f  (__VA_ARGS__);   \
+   result |= mfunc ## d  (__VA_ARGS__);   \
+   result |= mfunc ## ld (__VA_ARGS__);   \
+   result;				  \
+})
+
+
+#endif

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog            |   20 ++++++++++
 stdlib/bug-strtod.c  |  104 +++++++++++++++++++-------------------------------
 stdlib/bug-strtod2.c |   47 ++++++++++++++---------
 stdlib/tst-strtod.h  |   50 ++++++++++++++++++++++++
 stdlib/tst-strtod6.c |   99 ++++++++++++++++-------------------------------
 5 files changed, 172 insertions(+), 148 deletions(-)
 create mode 100644 stdlib/tst-strtod.h


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]