[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40358] trunk/blender/source/blender/ blenfont/intern: Blenfont: fix use incorrect clear of ascii glyph cache, leading to crash

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Sep 19 16:09:13 CEST 2011


Revision: 40358
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40358
Author:   blendix
Date:     2011-09-19 14:09:13 +0000 (Mon, 19 Sep 2011)
Log Message:
-----------
Blenfont: fix use incorrect clear of ascii glyph cache, leading to crash
when toggling use antialising user preference. Also fix some other use of
uninitialized memory found by valgrind.

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/intern/blf_dir.c
    trunk/blender/source/blender/blenfont/intern/blf_font.c
    trunk/blender/source/blender/blenfont/intern/blf_glyph.c

Modified: trunk/blender/source/blender/blenfont/intern/blf_dir.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_dir.c	2011-09-19 14:00:42 UTC (rev 40357)
+++ trunk/blender/source/blender/blenfont/intern/blf_dir.c	2011-09-19 14:09:13 UTC (rev 40358)
@@ -76,7 +76,7 @@
 	if (dir) /* already in the list ? just return. */
 		return;
 	
-	dir= (DirBLF *)MEM_mallocN(sizeof(DirBLF), "BLF_dir_add");
+	dir= (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add");
 	dir->path= BLI_strdup(path);
 	BLI_addhead(&global_font_dir, dir);
 }
@@ -104,7 +104,7 @@
 	if (!count)
 		return NULL;
 	
-	dirs= (char **)MEM_mallocN(sizeof(char *) * count, "BLF_dir_get");
+	dirs= (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get");
 	p= global_font_dir.first;
 	i= 0;
 	while (p) {

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-09-19 14:00:42 UTC (rev 40357)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-09-19 14:09:13 UTC (rev 40358)
@@ -511,7 +511,7 @@
 	FT_Error err;
 	char *mfile;
 
-	font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
+	font= (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new");
 	err= FT_New_Face(ft_lib, filename, 0, &font->face);
 	if (err) {
 		MEM_freeN(font);
@@ -553,7 +553,7 @@
 	FontBLF *font;
 	FT_Error err;
 
-	font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem");
+	font= (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem");
 	err= FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face);
 	if (err) {
 		MEM_freeN(font);

Modified: trunk/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2011-09-19 14:00:42 UTC (rev 40357)
+++ trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2011-09-19 14:09:13 UTC (rev 40358)
@@ -75,7 +75,7 @@
 {
 	GlyphCacheBLF *gc;
 
-	gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
+	gc= (GlyphCacheBLF *)MEM_callocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
 	gc->next= NULL;
 	gc->prev= NULL;
 	gc->size= font->size;
@@ -131,10 +131,8 @@
 				blf_glyph_free(g);
 			}
 		}
-	}
 
-	if(font->glyph_cache) {
-		memset(font->glyph_cache->glyph_ascii_table, 0, sizeof(font->glyph_cache->glyph_ascii_table));
+		memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
 	}
 }
 
@@ -250,20 +248,11 @@
 	if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
 		return NULL;
 
-	g= (GlyphBLF *)MEM_mallocN(sizeof(GlyphBLF), "blf_glyph_add");
-	g->next= NULL;
-	g->prev= NULL;
+	g= (GlyphBLF *)MEM_callocN(sizeof(GlyphBLF), "blf_glyph_add");
 	g->c= c;
 	g->idx= (FT_UInt)index;
-	g->tex= 0;
-	g->build_tex= 0;
-	g->bitmap= NULL;
 	g->xoff= -1;
 	g->yoff= -1;
-	g->uv[0][0]= 0.0f;
-	g->uv[0][1]= 0.0f;
-	g->uv[1][0]= 0.0f;
-	g->uv[1][1]= 0.0f;
 	bitmap= slot->bitmap;
 	g->width= bitmap.width;
 	g->height= bitmap.rows;




More information about the Bf-blender-cvs mailing list