This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Fix to get_temporary_buffer


Hi,

the below is a patchlet for a small problem that I'm seeing in our
get_temporary_buffer: INT_MAX is not ok on 64-bit platforms.

Tested x86/x86_64-linux, will apply tomorrow barring objections.

Paolo.

////////////
2004-10-09  Paolo Carlini  <pcarlini@suse.de>

	* include/std/std_memory.h (__get_temporary_buffer): Don't use
	INT_MAX, prefer numeric_limits<ptrdiff_t>::max(), ok on 64-bit
	platforms too.
	* testsuite/20_util/memory/auto_ptr/assign_neg.cc: Adjust dg-error
	line numbers.
diff -urN libstdc++-v3-orig/include/std/std_memory.h libstdc++-v3/include/std/std_memory.h
--- libstdc++-v3-orig/include/std/std_memory.h	2004-01-30 04:43:00.000000000 +0100
+++ libstdc++-v3/include/std/std_memory.h	2004-10-09 02:07:29.000000000 +0200
@@ -58,6 +58,7 @@
 #include <bits/stl_uninitialized.h>
 #include <bits/stl_raw_storage_iter.h>
 #include <debug/debug.h>
+#include <limits>
 
 namespace std
 {
@@ -73,8 +74,9 @@
     pair<_Tp*, ptrdiff_t>
     __get_temporary_buffer(ptrdiff_t __len, _Tp*)
     {
-      if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
-	__len = INT_MAX / sizeof(_Tp);
+      const ptrdiff_t __max = numeric_limits<ptrdiff_t>::max() / sizeof(_Tp);
+      if (__len > __max)
+	__len = __max;
       
       while (__len > 0) 
 	{
@@ -105,7 +107,7 @@
    * Provides the nothrow exception guarantee.
    */
   template<typename _Tp>
-    inline pair<_Tp*,ptrdiff_t>
+    inline pair<_Tp*, ptrdiff_t>
     get_temporary_buffer(ptrdiff_t __len)
     { return std::__get_temporary_buffer(__len, static_cast<_Tp*>(0)); }
 
diff -urN libstdc++-v3-orig/testsuite/20_util/memory/auto_ptr/assign_neg.cc libstdc++-v3/testsuite/20_util/memory/auto_ptr/assign_neg.cc
--- libstdc++-v3-orig/testsuite/20_util/memory/auto_ptr/assign_neg.cc	2004-09-23 23:27:25.000000000 +0200
+++ libstdc++-v3/testsuite/20_util/memory/auto_ptr/assign_neg.cc	2004-10-09 01:28:05.000000000 +0200
@@ -46,5 +46,5 @@
   test01();
   return 0;
 }
-// { dg-error "candidates" "" { target *-*-* } 222 } 
-// { dg-error "std::auto_ptr" "" { target *-*-* } 352 } 
+// { dg-error "candidates" "" { target *-*-* } 224 } 
+// { dg-error "std::auto_ptr" "" { target *-*-* } 354 } 

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