prevent uninitialized memory use when writing avi's.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 31 Jul 2012 10:34:42 +0000 (10:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 31 Jul 2012 10:34:42 +0000 (10:34 +0000)
source/blender/avi/intern/avi.c

index f64b693fb1c116b5f70167786c7b4a2e5b07d444..1c79c9b4237d8a3109e4c5cf885d3268d4280d60 100644 (file)
@@ -965,11 +965,15 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...)
        /* Allocate the new memory for the index entry */
 
        if (frame_num + 1 > movie->index_entries) {
-               temp = (AviIndexEntry *) MEM_mallocN((frame_num + 1) *
-                                                    (movie->header->Streams + 1) * sizeof(AviIndexEntry), "newidxentry");
+               const size_t entry_size = (movie->header->Streams + 1) * sizeof(AviIndexEntry);
+
                if (movie->entries != NULL) {
-                       memcpy(temp, movie->entries, movie->index_entries * (movie->header->Streams + 1) * sizeof(AviIndexEntry));
-                       MEM_freeN(movie->entries);
+                       temp = (AviIndexEntry *)MEM_reallocN(movie->entries, (frame_num + 1) * entry_size);
+                       /* clear new bytes */
+                       memset(&temp[movie->index_entries], 0, ((frame_num + 1) - movie->index_entries) * entry_size);
+               }
+               else {
+                       temp = (AviIndexEntry *) MEM_callocN((frame_num + 1) * entry_size, "newidxentry");
                }
 
                movie->entries = temp;