Commit 54c815bbba69d1ac775a5778c39b2cd7b201e559

sammy 2008-05-04T19:38:07

* Cast strings to unsigned char * before handling them to our internal methods, because the chars may be cast directly to int, causing crashes with 8-bit strings.

diff --git a/src/FTFont/FTFont.cpp b/src/FTFont/FTFont.cpp
index 8fe1592..7889b64 100644
--- a/src/FTFont/FTFont.cpp
+++ b/src/FTFont/FTFont.cpp
@@ -302,16 +302,16 @@ inline void FTFontImpl::RenderI(const T* string, int renderMode)
 }
 
 
-void FTFontImpl::Render(const wchar_t* string)
+void FTFontImpl::Render(const char * string)
 {
-    RenderI(string, FTGL::RENDER_FRONT | FTGL::RENDER_BACK | FTGL::RENDER_SIDE);
+    RenderI((const unsigned char *)string,
+            FTGL::RENDER_FRONT | FTGL::RENDER_BACK | FTGL::RENDER_SIDE);
 }
 
 
-void FTFontImpl::Render(const char * string)
+void FTFontImpl::Render(const wchar_t* string)
 {
-    RenderI((const unsigned char *)string,
-            FTGL::RENDER_FRONT | FTGL::RENDER_BACK | FTGL::RENDER_SIDE);
+    RenderI(string, FTGL::RENDER_FRONT | FTGL::RENDER_BACK | FTGL::RENDER_SIDE);
 }
 
 
@@ -418,7 +418,9 @@ void FTFontImpl::BBox(const char* string, const int start, const int end,
                       float& llx, float& lly, float& llz,
                       float& urx, float& ury, float& urz)
 {
-    return BBoxI(string, start, end, llx, lly, llz, urx, ury, urz);
+    /* The chars need to be unsigned because they are cast to int later */
+    return BBoxI((const unsigned char *)string, start, end,
+                 llx, lly, llz, urx, ury, urz);
 }
 
 
@@ -449,15 +451,16 @@ inline float FTFontImpl::AdvanceI(const T* string)
 }
 
 
-float FTFontImpl::Advance(const wchar_t* string)
+float FTFontImpl::Advance(const char* string)
 {
-    return AdvanceI(string);
+    /* The chars need to be unsigned because they are cast to int later */
+    return AdvanceI((const unsigned char *)string);
 }
 
 
-float FTFontImpl::Advance(const char* string)
+float FTFontImpl::Advance(const wchar_t* string)
 {
-    return AdvanceI((const unsigned char *)string);
+    return AdvanceI(string);
 }