From 1281fc99115392eb3f19f5e0a5c9b604fc72b27a Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 1 Dec 2016 18:18:30 +0000 Subject: [PATCH] vec.h (vec Prathamesh Kulkarni * vec.h (vec::quick_grow_cleared): Guard call to memset if len-oldlen != 0. (vec::safe_grow_cleared): Likewise. Co-Authored-By: Prathamesh Kulkarni From-SVN: r243125 --- gcc/ChangeLog | 7 +++++++ gcc/vec.h | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6768c5fd84c..b567324d4f3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-12-01 Richard Biener + Prathamesh Kulkarni + + * vec.h (vec::quick_grow_cleared): Guard call to + memset if len-oldlen != 0. + (vec::safe_grow_cleared): Likewise. + 2016-12-01 Uros Bizjak * config/i386/i386.md (*andndi3_doubleword): Depend on TARGET_SSE2. diff --git a/gcc/vec.h b/gcc/vec.h index 14fb2a673c1..aa93411132b 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -1092,8 +1092,10 @@ inline void vec::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::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); } -- 2.30.2