Fix writing beyond array bounds in codecvt/unshift/char/1.cc

Alexander Monakov amonakov@ispras.ru
Tue Apr 13 14:26:00 GMT 2010


Hi,

'size' definition seemingly does not account for a zero byte, and thus strcpy
call near the end of the test overwrites one byte beyond allocated memory,
which may lead to spurious test failures.  The patch simply bumps size to 24.
OK for trunk?

2010-04-13  Alexander Monakov  <amonakov@ispras.ru>

	* 22_locale/codecvt/unshift/char/1.cc (test01): Increase size to avoid
	writing past allocated memory.

diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/unshift/char/1.cc b/libstdc++-v3/testsuite/22_locale/codecvt/unshift/char/1.cc
index ba417af..8a45efc 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/unshift/char/1.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/unshift/char/1.cc
@@ -35,7 +35,7 @@ void test01()
   bool test __attribute__((unused)) = true;
   const char* 		c_lit = "black pearl jasmine tea";
   const char* 	        from_next;
-  int 			size = 23;
+  int 			size = 24;
   char* 		c_arr = new char[size];
   char*                 c_ref = new char[size];
   char*			to_next;



More information about the Gcc-patches mailing list