From: Brian Date: Mon, 24 Mar 2008 18:50:28 +0000 (-0600) Subject: gallium: fix REALLOC() to copy smaller of old/new sizes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4e398df6825f4b6d568f055b689e7d7043e2785e;p=mesa.git gallium: fix REALLOC() to copy smaller of old/new sizes --- diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h index 283f7fb8f5d..505626c60b5 100644 --- a/src/gallium/include/pipe/p_util.h +++ b/src/gallium/include/pipe/p_util.h @@ -107,10 +107,10 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size ) void *new_ptr = NULL; if (new_size != 0) { + unsigned copy_size = old_size < new_size ? old_size : new_size; new_ptr = MALLOC( new_size ); - - if( new_ptr && old_ptr ) { - memcpy( new_ptr, old_ptr, old_size ); + if (new_ptr && old_ptr && copy_size) { + memcpy( new_ptr, old_ptr, copy_size ); } }