Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-04-15 07:47:54 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-04-15 07:47:54 +0400
commit1fc9fabfbf3e3688d66264457abfa7df125fc1eb (patch)
tree6148d16c88f74990016119db2e8408fd34a7a7e0
parentc8798090a79edd893250aab1c30e09eec74451b5 (diff)
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.
-rw-r--r--source/blender/blenkernel/BKE_font.h8
-rw-r--r--source/blender/blenkernel/intern/font.c66
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;