This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

A patch for libio/tst-widetext.c


The problem is libio/tst-widetext.c uses too much stack memory for
buffer. With my kernel, running through make will push it over the
hard limit on my stack. This patch seems to fix it for me.

BTW, my old patch

2000-07-13  H.J. Lu  <hjl@gnu.org>

	* posix/regex.c (re_max_failures): Set to 4000.
 
deals with the same issue.


H.J.
--
2000-08-01  H.J. Lu  <hjl@gnu.org>

	* libio/tst-widetext.c (main): Use malloc instead of stack
	for buffers.

Index: libio/tst-widetext.c
===================================================================
RCS file: /work/cvs/gnu/glibc/libio/tst-widetext.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 tst-widetext.c
--- libio/tst-widetext.c	2000/07/25 23:42:26	1.1.1.1
+++ libio/tst-widetext.c	2000/08/01 16:05:48
@@ -36,10 +36,10 @@ int
 main (void)
 {
   char name[] = "/tmp/widetext.out.XXXXXX";
-  char mbbuf[SIZE];
-  char mb2buf[SIZE];
-  wchar_t wcbuf[SIZE];
-  wchar_t wc2buf[SIZE];
+  char *mbbuf = (char *) malloc (SIZE);
+  char *mb2buf = (char *) malloc (SIZE);
+  wchar_t *wcbuf = (wchar_t *) malloc (sizeof (wchar_t) * SIZE);
+  wchar_t *wc2buf = (wchar_t *) malloc (sizeof (wchar_t) * SIZE);
   size_t mbsize;
   size_t wcsize;
   int fd;
@@ -58,7 +58,7 @@ main (void)
     {
       printf ("%Zd: cannot read input file from standard input: %m\n",
 	      __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
    printf ("INFO: input file has %Zd bytes\n", mbsize);
@@ -69,7 +69,7 @@ main (void)
     char *inbuf = mbbuf;
     size_t inleft = mbsize;
     char *outbuf = (char *) wcbuf;
-    size_t outleft = sizeof (wcbuf);
+    size_t outleft = sizeof (wchar_t) * SIZE;
     size_t nonr;
 
     cd = iconv_open ("WCHAR_T", "UTF-8");
@@ -77,7 +77,7 @@ main (void)
       {
 	printf ("%Zd: cannot get iconv descriptor for conversion to UCS4\n",
 		__LINE__);
-	exit (1);
+	status = 1; goto done;
       }
 
     /* We must need only one call and there must be no losses.  */
@@ -86,7 +86,7 @@ main (void)
       {
 	printf ("%Zd: iconv performed %Zd nonreversible conversions\n",
 		__LINE__, nonr);
-	exit (1);
+	status = 1; goto done;
       }
 
     if  ((size_t) nonr == -1 )
@@ -94,24 +94,24 @@ main (void)
 	printf ("\
 %Zd: iconv returned with %Zd and errno = %m (inleft: %Zd, outleft: %Zd)\n",
 		__LINE__, nonr, inleft, outleft);
-	exit (1);
+	status = 1; goto done;
       }
 
     if (inleft != 0)
       {
 	printf ("%Zd: iconv didn't convert all input\n", __LINE__);
-	exit (1);
+	status = 1; goto done;
       }
 
     iconv_close (cd);
 
-    if ((sizeof (wcbuf) - outleft) % sizeof (wchar_t) != 0)
+    if (((sizeof (wchar_t) * SIZE) - outleft) % sizeof (wchar_t) != 0)
       {
 	printf ("%Zd: iconv converted not complete wchar_t\n", __LINE__);
-	exit (1);
+	status = 1; goto done;
       }
 
-    wcsize = (sizeof (wcbuf) - outleft) / sizeof (wchar_t);
+    wcsize = ((sizeof (wchar_t) * SIZE) - outleft) / sizeof (wchar_t);
     assert (wcsize + 1 <= SIZE);
   }
 
@@ -123,7 +123,7 @@ main (void)
   if (fd == -1)
     {
       printf ("%Zd: cannot open temporary file: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   unlink (name);
@@ -132,7 +132,7 @@ main (void)
   if (fp == NULL)
     {
       printf ("%Zd: fdopen of temp file for writing failed: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   for (n = 0; n < wcsize; ++n)
@@ -140,7 +140,7 @@ main (void)
       if (fputwc (wcbuf[n], fp) == WEOF)
 	{
 	  printf ("%Zd: fputwc failed: %m\n", __LINE__);
-	  exit (1);
+	  status = 1; goto done;
 	}
     }
 
@@ -149,7 +149,7 @@ main (void)
     {
       printf ("%Zd: fclose after single-character writing failed (%d): %m\n",
 	      __LINE__, res);
-      exit (1);
+      status = 1; goto done;
     }
 
   lseek (fd, SEEK_SET, 0);
@@ -157,7 +157,7 @@ main (void)
   if (fp == NULL)
     {
       printf ("%Zd: fdopen of temp file for reading failed: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   for (n = 0; n < wcsize; ++n)
@@ -166,7 +166,7 @@ main (void)
       if (wch == WEOF)
 	{
 	  printf ("%Zd: fgetwc failed (idx %Zd): %m\n", __LINE__, n);
-	  exit (1);
+	  status = 1; goto done;
 	}
       wc2buf[n] = wch;
     }
@@ -188,7 +188,7 @@ main (void)
     {
       printf ("%Zd: fclose after single-character reading failed (%d): %m\n",
 	      __LINE__, res);
-      exit (1);
+      status = 1; goto done;
     }
 
   /* Just make sure there are no two errors which hide each other, read the
@@ -199,7 +199,7 @@ main (void)
   if (fp == NULL)
     {
       printf ("%Zd: fdopen of temp file for reading failed: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   if (fread (mb2buf, 1, mbsize, fp) != mbsize)
@@ -228,7 +228,7 @@ main (void)
     {
       printf ("%Zd: fclose after single-character reading failed (%d): %m\n",
 	      __LINE__, res);
-      exit (1);
+      status = 1; goto done;
     }
 
   /* Now to reading and writing line-wise.  */
@@ -237,7 +237,7 @@ main (void)
   if (fd == -1)
     {
       printf ("%Zd: cannot open temporary file: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   unlink (name);
@@ -246,7 +246,7 @@ main (void)
   if (fp == NULL)
     {
       printf ("%Zd: fdopen of temp file for writing failed: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   for (wcp = wcbuf; wcp < &wcbuf[wcsize]; )
@@ -277,7 +277,7 @@ main (void)
     {
       printf ("%Zd: fclose after line-wise writing failed (%d): %m\n",
 	      __LINE__, res);
-      exit (1);
+      status = 1; goto done;
     }
 
   lseek (fd, SEEK_SET, 0);
@@ -285,7 +285,7 @@ main (void)
   if (fp == NULL)
     {
       printf ("%Zd: fdopen of temp file for reading failed: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   for (wcp = wc2buf; wcp < &wc2buf[wcsize]; )
@@ -323,7 +323,7 @@ main (void)
     {
       printf ("%Zd: fclose after single-character reading failed (%d): %m\n",
 	      __LINE__, res);
-      exit (1);
+      status = 1; goto done;
     }
 
   /* Just make sure there are no two errors which hide each other, read the
@@ -334,7 +334,7 @@ main (void)
   if (fp == NULL)
     {
       printf ("%Zd: fdopen of temp file for reading failed: %m\n", __LINE__);
-      exit (1);
+      status = 1; goto done;
     }
 
   if (fread (mb2buf, 1, mbsize, fp) != mbsize)
@@ -363,8 +363,13 @@ main (void)
     {
       printf ("%Zd: fclose after single-character reading failed (%d): %m\n",
 	      __LINE__, res);
-      exit (1);
+      status = 1; goto done;
     }
 
+done:
+  free (mbbuf);
+  free (mb2buf);
+  free (wcbuf);
+  free (wc2buf);
   return status;
 }

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