gallium: fix REALLOC() to copy smaller of old/new sizes
authorBrian <brian.paul@tungstengraphics.com>
Mon, 24 Mar 2008 18:50:28 +0000 (12:50 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Mon, 24 Mar 2008 18:51:18 +0000 (12:51 -0600)
src/gallium/include/pipe/p_util.h

index 283f7fb8f5dd588feb040a04c41b9ca1316c2f4b..505626c60b5bc2879913aa6266bc0761df3aa011 100644 (file)
@@ -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 );
       }
    }