[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56696] trunk/blender/source/blender: quiet sign conversion warnings and reduce sign conversion for BLI_string, and BLF.

Campbell Barton ideasman42 at gmail.com
Sun May 12 08:33:24 CEST 2013


Revision: 56696
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56696
Author:   campbellbarton
Date:     2013-05-12 06:33:21 +0000 (Sun, 12 May 2013)
Log Message:
-----------
quiet sign conversion warnings and reduce sign conversion for BLI_string, and BLF.

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/intern/blf_font.c
    trunk/blender/source/blender/blenfont/intern/blf_glyph.c
    trunk/blender/source/blender/blenfont/intern/blf_internal.h
    trunk/blender/source/blender/blenfont/intern/blf_internal_types.h
    trunk/blender/source/blender/blenlib/intern/string.c
    trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c
    trunk/blender/source/blender/blenlib/intern/string_utf8.c

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2013-05-12 06:33:21 UTC (rev 56696)
@@ -58,6 +58,9 @@
 #include "blf_internal_types.h"
 #include "blf_internal.h"
 
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
 
 /* freetype2 handle ONLY for this file!. */
 static FT_Library ft_lib;
@@ -72,7 +75,7 @@
 	FT_Done_FreeType(ft_lib);
 }
 
-void blf_font_size(FontBLF *font, int size, int dpi)
+void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
 {
 	GlyphCacheBLF *gc;
 	FT_Error err;

Modified: trunk/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2013-05-12 06:33:21 UTC (rev 56696)
@@ -55,8 +55,11 @@
 #include "blf_internal_types.h"
 #include "blf_internal.h"
 
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
 
-GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
+GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, unsigned int size, unsigned int dpi)
 {
 	GlyphCacheBLF *p;
 
@@ -167,18 +170,18 @@
 		gc->textures = (GLuint *)realloc((void *)gc->textures, sizeof(GLuint) * gc->ntex);
 	}
 
-	gc->p2_width = blf_next_p2((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2));
+	gc->p2_width = (int)blf_next_p2((unsigned int)((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2)));
 	if (gc->p2_width > font->max_tex_size)
 		gc->p2_width = font->max_tex_size;
 
 	i = (int)((gc->p2_width - (gc->pad * 2)) / gc->max_glyph_width);
-	gc->p2_height = blf_next_p2(((gc->num_glyphs / i) + 1) * gc->max_glyph_height);
+	gc->p2_height = (int)blf_next_p2((unsigned int)(((gc->num_glyphs / i) + 1) * gc->max_glyph_height));
 
 	if (gc->p2_height > font->max_tex_size)
 		gc->p2_height = font->max_tex_size;
 
 	tot_mem = gc->p2_width * gc->p2_height;
-	buf = (unsigned char *)MEM_callocN(tot_mem, __func__);
+	buf = (unsigned char *)MEM_callocN((size_t)tot_mem, __func__);
 
 	glGenTextures(1, &gc->textures[gc->cur_tex]);
 	glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = gc->textures[gc->cur_tex]));
@@ -269,8 +272,8 @@
 			}
 		}
 
-		g->bitmap = (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap");
-		memcpy((void *)g->bitmap, (void *)bitmap.buffer, g->width * g->height);
+		g->bitmap = (unsigned char *)MEM_mallocN((size_t)(g->width * g->height), "glyph bitmap");
+		memcpy((void *)g->bitmap, (void *)bitmap.buffer, (size_t)(g->width * g->height));
 	}
 
 	g->advance = ((float)slot->advance.x) / 64.0f;

Modified: trunk/blender/source/blender/blenfont/intern/blf_internal.h
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_internal.h	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenfont/intern/blf_internal.h	2013-05-12 06:33:21 UTC (rev 56696)
@@ -50,7 +50,7 @@
 struct FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size);
 void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
 
-void blf_font_size(struct FontBLF *font, int size, int dpi);
+void blf_font_size(struct FontBLF *font, unsigned int size, unsigned int dpi);
 void blf_font_draw(struct FontBLF *font, const char *str, size_t len);
 void blf_font_draw_ascii(struct FontBLF *font, const char *str, size_t len);
 int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth);
@@ -62,7 +62,7 @@
 float blf_font_fixed_width(struct FontBLF *font);
 void blf_font_free(struct FontBLF *font);
 
-struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font, int size, int dpi);
+struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font, unsigned int size, unsigned int dpi);
 struct GlyphCacheBLF *blf_glyph_cache_new(struct FontBLF *font);
 void blf_glyph_cache_clear(struct FontBLF *font);
 void blf_glyph_cache_free(struct GlyphCacheBLF *gc);

Modified: trunk/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_internal_types.h	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenfont/intern/blf_internal_types.h	2013-05-12 06:33:21 UTC (rev 56696)
@@ -36,10 +36,10 @@
 	struct GlyphCacheBLF *prev;
 
 	/* font size. */
-	int size;
+	unsigned int size;
 
 	/* and dpi. */
-	int dpi;
+	unsigned int dpi;
 
 	/* and the glyphs. */
 	ListBase bucket[257];
@@ -51,7 +51,7 @@
 	GLuint *textures;
 
 	/* size of the array. */
-	int ntex;
+	unsigned int ntex;
 
 	/* and the last texture, aka. the current texture. */
 	int cur_tex;
@@ -63,7 +63,7 @@
 	int y_offs;
 
 	/* and the space from one to other. */
-	unsigned int pad;
+	int pad;
 
 	/* and the bigger glyph in the font. */
 	int max_glyph_width;
@@ -194,16 +194,16 @@
 	rctf clip_rec;
 
 	/* font dpi (default 72). */
-	int dpi;
+	unsigned int dpi;
 
 	/* font size. */
-	int size;
+	unsigned int size;
 
 	/* max texture size. */
 	int max_tex_size;
 
 	/* cache current OpenGL texture to save calls into the API */
-	int tex_bind_state;
+	unsigned int tex_bind_state;
 
 	/* font options. */
 	int flags;

Modified: trunk/blender/source/blender/blenlib/intern/string.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string.c	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenlib/intern/string.c	2013-05-12 06:33:21 UTC (rev 56696)
@@ -43,6 +43,10 @@
 
 #include "BLI_utildefines.h"
 
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
+
 /**
  * Duplicates the first \a len bytes of cstring \a str
  * into a newly mallocN'd string and returns it. \a str
@@ -146,7 +150,7 @@
 	BLI_assert(count > 0);
 	BLI_assert(format != NULL);
 
-	n = vsnprintf(buffer, count, format, arg);
+	n = (size_t)vsnprintf(buffer, count, format, arg);
 
 	if (n != -1 && n < count) {
 		buffer[n] = '\0';
@@ -459,7 +463,7 @@
 
 	/* same number of digits, compare size of number */
 	if (numdigit > 0) {
-		int compare = strncmp(p1, p2, numdigit);
+		int compare = (int)strncmp(p1, p2, (size_t)numdigit);
 
 		if (compare != 0)
 			return compare;

Modified: trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c	2013-05-12 06:33:21 UTC (rev 56696)
@@ -36,6 +36,10 @@
 
 #include "BLI_string_cursor_utf8.h" /* own include */
 
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
+
 typedef enum strCursorDelimType {
 	STRCUR_DELIM_NONE,
 	STRCUR_DELIM_ALPHANUMERIC,

Modified: trunk/blender/source/blender/blenlib/intern/string_utf8.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string_utf8.c	2013-05-12 05:54:33 UTC (rev 56695)
+++ trunk/blender/source/blender/blenlib/intern/string_utf8.c	2013-05-12 06:33:21 UTC (rev 56696)
@@ -41,6 +41,10 @@
 
 #include "BLI_string_utf8.h"  /* own include */
 
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
+
 /* from libswish3, originally called u8_isvalid(),
  * modified to return the index of the bad character (byte index not utf).
  * http://svn.swish-e.org/libswish3/trunk/src/libswish3/utf8.c r3044 - campbell */
@@ -143,7 +147,7 @@
 		}
 		else {
 			/* strip, keep looking */
-			memmove(str, str + 1, length);
+			memmove(str, str + 1, (size_t)length);
 			tot++;
 		}
 	}
@@ -221,7 +225,7 @@
 	BLI_assert(maxncpy != 0);
 
 	while (*src && len < maxncpy) { /* XXX can still run over the buffer because utf8 size isn't known :| */
-		len += BLI_str_utf8_from_unicode(*src++, dst + len);
+		len += BLI_str_utf8_from_unicode((unsigned int)*src++, dst + len);
 	}
 
 	dst[len] = '\0';
@@ -235,7 +239,7 @@
 	size_t len = 0;
 
 	while (*src) {
-		len += BLI_str_utf8_from_unicode(*src++, NULL);
+		len += BLI_str_utf8_from_unicode((unsigned int)*src++, NULL);
 	}
 
 	return len;
@@ -292,7 +296,7 @@
 
 size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst_w, const char *__restrict src_c, const size_t maxncpy)
 {
-	int len = 0;
+	size_t len = 0;
 
 	if (dst_w == NULL || src_c == NULL) {
 		return 0;
@@ -443,7 +447,8 @@
  **/
 unsigned int BLI_str_utf8_as_unicode(const char *p)
 {
-	int i, mask = 0, len;
+	int i, len;
+	unsigned int mask = 0;
 	unsigned int result;
 	const unsigned char c = (unsigned char) *p;
 
@@ -458,7 +463,8 @@
 /* variant that increments the length */
 unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index)
 {
-	int i, mask = 0, len;
+	int i, len;
+	unsigned mask = 0;
 	unsigned int result;
 	const unsigned char c = (unsigned char) *p;
 
@@ -466,13 +472,14 @@
 	if (UNLIKELY(len == -1))
 		return BLI_UTF8_ERR;
 	UTF8_GET (result, p, i, mask, len, BLI_UTF8_ERR);
-	*index += len;
+	*index += (size_t)len;
 	return result;
 }
 
 unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index)
 {
-	int i, mask = 0, len;
+	int i, len;
+	unsigned int mask = 0;
 	unsigned int result;
 	const unsigned char c = (unsigned char) *p;
 
@@ -482,7 +489,7 @@
 		return c;
 	}
 	UTF8_GET (result, p, i, mask, len, BLI_UTF8_ERR);
-	*index += len;
+	*index += (size_t)len;
 	return result;
 }
 
@@ -490,7 +497,8 @@
  * note, currently this also falls back to latin1 for text drawing. */
 unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)
 {
-	int i, mask = 0, len;
+	int i, len;
+	unsigned int mask = 0;
 	unsigned int result;
 	unsigned char c;
 
@@ -527,7 +535,7 @@
 	UTF8_GET (result, p, i, mask, len, '?');
 #endif
 
-	*index += len;
+	*index += (size_t)len;
 	return result;
 }
 
@@ -547,8 +555,8 @@
 {
 	/* If this gets modified, also update the copy in g_string_insert_unichar() */
 	unsigned int len = 0;
-	int first;
-	int i;
+	unsigned int first;
+	unsigned int i;
 
 	if (c < 0x80) {
 		first = 0;




More information about the Bf-blender-cvs mailing list