Patchwork libstdc++-v3: add more verifications to testsuite

login
register
mail settings
Submitter Kees Cook
Date June 25, 2010, 10:50 p.m.
Message ID <20100625225052.GE4175@outflux.net>
Download mbox | patch
Permalink /patch/57004/
State New
Headers show

Comments

Kees Cook - June 25, 2010, 10:50 p.m.
Hello,

Here is a patch that adds additional tests to the libstdc++-v3 test suite.
Ubuntu builds packages with -D_FORTIFY_SOURCE=2, so running the suite
shows a few minor warnings.  This cleans them up by providing additional
sanity checks around freopen, fgets, and fwrite, as already done in other
places in the testsuite.

Thanks,

-Kees

2010-06-25  Kees Cook  <kees.cook@canonical.com>

	* testsuite/27_io/ios_base/sync_with_stdio/1.cc: verify freopen.
	* testsuite/27_io/objects/wchar_t/9520.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/9661-1.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/12048-2.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/12048-4.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/11.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/12048-1.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/12048-3.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/10.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/12048-5.cc: Likewise.
	* testsuite/27_io/objects/char/9661-1.cc: Likewise.
	* testsuite/27_io/objects/char/12048-2.cc: Likewise.
	* testsuite/27_io/objects/char/12048-4.cc: Likewise.
	* testsuite/27_io/objects/char/9.cc: Likewise.
	* testsuite/27_io/objects/char/12048-1.cc: Likewise.
	* testsuite/27_io/objects/char/12048-3.cc: Likewise.
	* testsuite/27_io/objects/char/12048-5.cc: Likewise.
	* testsuite/ext/stdio_sync_filebuf/wchar_t/12077.cc: Likewise.
	* testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc: verify fgets.
	* testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc: verify
	fwrite.
	* testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc: Likewise.
	* testsuite/ext/stdio_sync_filebuf/char/1.cc: Likewise.
Magnus Granberg - June 25, 2010, 11:20 p.m.
lördag 26 juni 2010 00.50.52 skrev  Kees Cook:
> Hello,
> 
> Here is a patch that adds additional tests to the libstdc++-v3 test suite.
> Ubuntu builds packages with -D_FORTIFY_SOURCE=2, so running the suite
> shows a few minor warnings.  This cleans them up by providing additional
> sanity checks around freopen, fgets, and fwrite, as already done in other
> places in the testsuite.
> 
> Thanks,
> 
> -Kees
Gentoo build the packages with -D_FORTIY_SOURCES=2 too so fixes to the 
testsuite are welcome.

/Magnus
Paolo Carlini - June 25, 2010, 11:29 p.m.
On 06/26/2010 12:50 AM, Kees Cook wrote:
> Hello,
>
> Here is a patch that adds additional tests to the libstdc++-v3 test suite.
> Ubuntu builds packages with -D_FORTIFY_SOURCE=2, so running the suite
> shows a few minor warnings.  This cleans them up by providing additional
> sanity checks around freopen, fgets, and fwrite, as already done in other
> places in the testsuite.
>   
Ok... but change the tests to simply:
   
    VERIFY( std::freopen("ios_base_members_static-1.txt", "w", stderr) );

and so on, because we are trying to minimize the uses of C-style NULLs.

Paolo.

Patch

Index: libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc	(working copy)
@@ -41,7 +41,7 @@  void
 test01()
 {
   std::ios_base::sync_with_stdio();
-  std::freopen("ios_base_members_static-1.txt", "w", stderr);
+  VERIFY( std::freopen("ios_base_members_static-1.txt", "w", stderr) != NULL );
  
   for (int i = 0; i < 2; i++)
     {
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc	(working copy)
@@ -38,7 +38,7 @@  void test01()
   locale loc (locale("de_DE.ISO-8859-15@euro"));
   locale::global(loc); // Set locale for stdin
 
-  freopen(name, "r", stdin);
+  VERIFY( freopen(name, "r", stdin) != NULL );
 
   wcin.imbue(loc);
 
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc	(working copy)
@@ -67,7 +67,7 @@  bool test01()
       exit(0);
     }
 
-  freopen(name, "r", stdin);
+  VERIFY( freopen(name, "r", stdin) != NULL );
   s1.wait();
 
   wint_t c1 = fgetwc(stdin);
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc	(working copy)
@@ -23,7 +23,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   wchar_t c1;
   std::wint_t c2;
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc	(working copy)
@@ -23,7 +23,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   wchar_t buf[2];
   VERIFY( std::wcin.rdbuf()->sgetn(buf, 2) == 2 );
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/11.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/11.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/11.cc	(working copy)
@@ -90,7 +90,7 @@  void test11()
   };
   size_t i_size = wcslen(i_lit);
 
-  freopen(name, "w", stdout);
+  VERIFY( freopen(name, "w", stdout) != NULL );
   
   wcout.write(i_lit, i_size);
   wcout.flush();
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc	(working copy)
@@ -26,7 +26,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   wchar_t c1;
   wchar_t c2;
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc	(working copy)
@@ -27,7 +27,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   wchar_t buf[2];
   VERIFY( std::wcin.rdbuf()->sgetn(buf, 2) == 2 );
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc	(working copy)
@@ -95,7 +95,7 @@  void test10()
   VERIFY( n == e_size );
   fclose(file);
 
-  freopen(name, "r", stdin);
+  VERIFY( freopen(name, "r", stdin) != NULL );
   
   wchar_t* wbuf = new wchar_t[i_size + 10];
   wcin.read(wbuf, i_size + 10);
Index: libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc	(working copy)
@@ -29,7 +29,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   wchar_t c1;
   std::wint_t c2;
Index: libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc	(working copy)
@@ -68,7 +68,7 @@  bool test01()
       exit(0);
     }
 
-  freopen(name, "r", stdin);
+  VERIFY( freopen(name, "r", stdin) != NULL );
   s1.wait();
 
   int c1 = fgetc(stdin);
Index: libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc	(working copy)
@@ -24,7 +24,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   char c1;
   int c2;
Index: libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc	(working copy)
@@ -24,7 +24,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   char buf[2];
   VERIFY( std::cin.rdbuf()->sgetn(buf, 2) == 2 );
Index: libstdc++-v3/testsuite/27_io/objects/char/9.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/9.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/9.cc	(working copy)
@@ -34,7 +34,7 @@  void test09()
   fputs("abc\n", fout);
   fclose(fout);
 
-  freopen(name, "r", stdin);
+  VERIFY( freopen(name, "r", stdin) != NULL );
  
   // basic_streambuf::showmanyc returns 0.
   VERIFY( 0 == std::cin.rdbuf()->in_avail() );
Index: libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc	(working copy)
@@ -28,7 +28,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   char c1;
   char c2;
Index: libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc	(working copy)
@@ -25,7 +25,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   char buf[2];
   VERIFY( std::cin.rdbuf()->sgetn(buf, 2) == 2 );
Index: libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc	(working copy)
@@ -33,7 +33,7 @@ 
 void
 test01()
 {
-  std::freopen("cin_unget-1.txt", "r", stdin);
+  VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) != NULL );
 
   char c1;
   int c2;
Index: libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc	(working copy)
@@ -44,7 +44,7 @@  void test02()
   
   FILE* in = fopen(name, "r");
   char str[256];
-  fgets(str, 256, in);
+  VERIFY( fgets(str, 256, in) != NULL );
   VERIFY( !strcmp(str, "Hello, world") );
   fclose(in);
 }
Index: libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc	(revision 161298)
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc	(working copy)
@@ -161,7 +161,7 @@  void test02()
   const char* name = "tmp_11544-2";
   
   FILE* f = fopen(name, "w");
-  fwrite("aaaab", 1, 5, f);
+  VERIFY( fwrite("aaaab", 1, 5, f) == 5 );
   fclose(f);
   
   wifstream in;
Index: libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc
===================================================================
--- libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc	(working copy)
@@ -33,7 +33,7 @@  void test01()
   const char* name = "stdiobuf-1.txt";
 
   FILE* fout = fopen(name, "w");
-  fwrite(c_lit, 1, size, fout);
+  VERIFY( fwrite(c_lit, 1, size, fout) == size );
   fclose(fout);
 
   FILE* fin = fopen(name, "r");
Index: libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12077.cc
===================================================================
--- libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12077.cc	(revision 161298)
+++ libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12077.cc	(working copy)
@@ -64,7 +64,7 @@  void test01()
   fputs(str, file);
   fclose(file);
   
-  freopen(name, "r", stdin);
+  VERIFY( freopen(name, "r", stdin) != NULL );
   
   streamsize n = wcin.rdbuf()->in_avail();
   while (n--)
Index: libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/1.cc
===================================================================
--- libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/1.cc	(revision 161298)
+++ libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/1.cc	(working copy)
@@ -33,7 +33,7 @@  void test01()
   const char* name = "stdiobuf-1.txt";
 
   FILE* fout = fopen(name, "w");
-  fwrite(c_lit, 1, size, fout);
+  VERIFY( fwrite(c_lit, 1, size, fout) == size );
   fclose(fout);
 
   FILE* fin = fopen(name, "r");