From 1fc9fabfbf3e3688d66264457abfa7df125fc1eb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 15 Apr 2011 03:47:54 +0000 Subject: possible fix [#26930] Blender 2.57 Shuts down when trying to edit 3D text can't test but this avoids using strncat which is giving problems. --- source/blender/blenkernel/BKE_font.h | 8 ++-- source/blender/blenkernel/intern/font.c | 66 +++++++++++++++------------------ 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h index 7f4e7c208f6..2195b370a5f 100644 --- a/source/blender/blenkernel/BKE_font.h +++ b/source/blender/blenkernel/BKE_font.h @@ -84,10 +84,10 @@ struct chartrans *BKE_text_to_curve(struct Scene *scene, struct Object *ob, int int BKE_font_getselection(struct Object *ob, int *start, int *end); -void chtoutf8(unsigned long c, char *o); -void wcs2utf8s(char *dst, wchar_t *src); -int wcsleninu8(wchar_t *src); -int utf8towchar(wchar_t *w, char *c); +size_t chtoutf8(const unsigned long c, char o[4]); +void wcs2utf8s(char *dst, const wchar_t *src); +size_t wcsleninu8(wchar_t *src); +size_t utf8towchar(wchar_t *w, const char *c); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 5c1922b469b..0c722d81f45 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -67,69 +67,61 @@ static ListBase ttfdata= {NULL, NULL}; /* UTF-8 <-> wchar transformations */ -void -chtoutf8(unsigned long c, char *o) +size_t chtoutf8(const unsigned long c, char o[4]) { // Variables and initialization -/* memset(o, 0, 16); */ +/* memset(o, 0, 4); */ // Create the utf-8 string - if (c < 0x80) - { + if (c < 0x80) { o[0] = (char) c; + return 1; } - else if (c < 0x800) - { + else if (c < 0x800) { o[0] = (0xC0 | (c>>6)); o[1] = (0x80 | (c & 0x3f)); + return 2; } - else if (c < 0x10000) - { + else if (c < 0x10000) { o[0] = (0xe0 | (c >> 12)); o[1] = (0x80 | (c >>6 & 0x3f)); o[2] = (0x80 | (c & 0x3f)); + return 3; } - else if (c < 0x200000) - { - o[0] = (0xf0 | (c>>18)); - o[1] = (0x80 | (c >>12 & 0x3f)); - o[2] = (0x80 | (c >> 6 & 0x3f)); - o[3] = (0x80 | (c & 0x3f)); + else if (c < 0x200000) { + o[0] = (0xf0 | (c>>18)); + o[1] = (0x80 | (c >>12 & 0x3f)); + o[2] = (0x80 | (c >> 6 & 0x3f)); + o[3] = (0x80 | (c & 0x3f)); + return 4; } + + /* should we assert here? */ + return 0; } -void -wcs2utf8s(char *dst, wchar_t *src) +void wcs2utf8s(char *dst, const wchar_t *src) { - /* NULL terminator not needed */ - char ch[4]; - - while(*src) - { - memset(ch, 0, sizeof(ch)); - chtoutf8(*src++, ch); - dst= strncat(dst, ch, sizeof(ch)); + while(*src) { + dst += chtoutf8(*src++, dst); } + + *dst= '\0'; } -int -wcsleninu8(wchar_t *src) +size_t wcsleninu8(wchar_t *src) { - char ch[16]; - int len = 0; + char ch_dummy[4]; + size_t len = 0; - while(*src) - { - memset(ch, 0, 16); - chtoutf8(*src++, ch); - len = len + strlen(ch); + while(*src) { + len += chtoutf8(*src++, ch_dummy); } return len; } -static int -utf8slen(const char *strc) +static size_t utf8slen(const char *strc) { int len=0; @@ -172,7 +164,7 @@ only a single input character is consumed. */ -int utf8towchar(wchar_t *w, char *c) +size_t utf8towchar(wchar_t *w, const char *c) { int len=0; -- cgit v1.2.3