[MPlayer-dev-eng] [RFC] always memset structs to 0 in libass

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Mar 28 19:36:54 CET 2009


Hello,
I originally stumbled over this because of valgrind warnings.
The real issue is that you can't just use the default
hashmap_hash/hashmap_key_compare with structs, but I leave that to the
libass maintainer(s).
Independent of that, I consider it a good idea to initialize all
structs to 0 anyway, simply because
1) it makes it easier to extend those structs without running into weird
random bugs
2) for what I can tell there are only exactly _three_ places where this
is currently not done, so it makes things more consistent as well.

Attached is the proposed patch for this.
-------------- next part --------------
Index: libass/ass_render.c
===================================================================
--- libass/ass_render.c	(revision 29081)
+++ libass/ass_render.c	(working copy)
@@ -455,6 +455,7 @@
 	cur_top = top-by;
 
 	// Query cache
+	memset(&hk, 0, sizeof(hk));
 	memcpy(&hk.a, last_hash, sizeof(*last_hash));
 	memcpy(&hk.b, hash, sizeof(*hash));
 	hk.aw = aw;
@@ -1429,6 +1430,7 @@
 	int error;
 	glyph_hash_val_t* val;
 	glyph_hash_key_t key;
+	memset(&key, 0, sizeof(key));
 	key.font = render_context.font;
 	key.size = render_context.font_size;
 	key.ch = symbol;
@@ -1873,6 +1875,7 @@
 /**
  * \brief Main ass rendering function, glues everything together
  * \param event event to render
+ * \param event_images struct containing resulting images, will also be initialized
  * Process event, appending resulting ass_image_t's to images_root.
  */
 static int ass_render_event(ass_event_t* event, event_images_t* event_images)
@@ -2166,6 +2169,7 @@
 	for (i = 0; i < text_info.length; ++i)
 		get_bitmap_glyph(text_info.glyphs + i);
 
+	memset(event_images, 0, sizeof(*event_images));
 	event_images->top = device_y - d6_to_int(text_info.lines[0].asc);
 	event_images->height = d6_to_int(text_info.height);
 	event_images->detect_collisions = render_context.detect_collisions;


More information about the MPlayer-dev-eng mailing list