Fixed null string bug in BBox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 0e3f5c3..438105a 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -105,7 +105,8 @@ void FTFont::BBox( const char* string,
float& llx, float& lly, float& llz, float& urx, float& ury, float& urz)
{
FTBBox totalBBox;
- if( NULL != *string)
+
+ if((NULL != string) && ('\0' != *string))
{
const unsigned char* c = (unsigned char*)string;
@@ -140,7 +141,7 @@ void FTFont::BBox( const wchar_t* string,
{
FTBBox totalBBox;
- if( NULL != *string)
+ if((NULL != string) && ('\0' != *string))
{
const wchar_t* c = string;
diff --git a/test/FTFont-Test.cpp b/test/FTFont-Test.cpp
index e3272d9..7d98107 100755
--- a/test/FTFont-Test.cpp
+++ b/test/FTFont-Test.cpp
@@ -166,9 +166,18 @@ class FTFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_DOUBLES_EQUAL( 134.28, urx, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 61.12, ury, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.00, urz, 0.01);
-
+
testFont->BBox( BAD_UNICODE_TEST_STRING, llx, lly, llz, urx, ury, urz);
-
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, llx, 0.01);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lly, 0.01);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, llz, 0.01);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, urx, 0.01);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, ury, 0.01);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, urz, 0.01);
+
+ testFont->BBox( (char*)0, llx, lly, llz, urx, ury, urz);
+
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, llx, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lly, 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, llz, 0.01);