diff mbox

PR78629

Message ID CAAgBjM=oqXiTLUfRZW5wxo_p4C=8e-S-fHRvkLiRxKr_fbpM-w@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni Dec. 1, 2016, 1:27 p.m. UTC
Hi Richard,
I tested your fix for the patch with ubsan stage-1 built gcc, and it
fixes the error.
Is it OK to commit if bootstrap+test passes on x86_64-unknown-linux-gnu ?

Thanks,
Prathamesh
2016-12-01  Richard Biener  <rguenther@suse.de>
	    Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	PR middle-end/78629
	* vec.h (vec<T, A, vl_embed>::quick_grow_cleared): Guard call to
	memset if len-oldlen != 0.
	(vec<T, va_heap, vl_ptr>::safe_grow_cleared): Likewise.

Comments

Richard Biener Dec. 1, 2016, 1:28 p.m. UTC | #1
On Thu, 1 Dec 2016, Prathamesh Kulkarni wrote:

> Hi Richard,

> I tested your fix for the patch with ubsan stage-1 built gcc, and it

> fixes the error.

> Is it OK to commit if bootstrap+test passes on x86_64-unknown-linux-gnu ?


Ok.

Richard.
diff mbox

Patch

diff --git a/gcc/vec.h b/gcc/vec.h
index 14fb2a6..aa93411 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1092,8 +1092,10 @@  inline void
 vec<T, A, vl_embed>::quick_grow_cleared (unsigned len)
 {
   unsigned oldlen = length ();
+  size_t sz = sizeof (T) * (len - oldlen);
   quick_grow (len);
-  memset (&(address ()[oldlen]), 0, sizeof (T) * (len - oldlen));
+  if (sz != 0)
+    memset (&(address ()[oldlen]), 0, sz);
 }
 
 
@@ -1605,8 +1607,10 @@  inline void
 vec<T, va_heap, vl_ptr>::safe_grow_cleared (unsigned len MEM_STAT_DECL)
 {
   unsigned oldlen = length ();
+  size_t sz = sizeof (T) * (len - oldlen);
   safe_grow (len PASS_MEM_STAT);
-  memset (&(address ()[oldlen]), 0, sizeof (T) * (len - oldlen));
+  if (sz != 0)
+    memset (&(address ()[oldlen]), 0, sz);
 }