bug 738197 - handle potential failures in gfxFont::GetShapedWord more robustly. r=roc
☠☠ backed out by d0dfb71a2df9 ☠ ☠
authorJonathan Kew <jfkthame@gmail.com>
Fri, 23 Mar 2012 12:13:33 +0000
changeset 91958 1152d14294df24ac807730e4861075a5a81d8474
parent 91957 b3e429486693a64a17ca096b30fd47d038623e1f
child 91959 18c70ab50559920a2ddfa7e42b934f785874de3b
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs738197
milestone14.0a1
bug 738197 - handle potential failures in gfxFont::GetShapedWord more robustly. r=roc
gfx/thebes/gfxFont.cpp
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -1930,45 +1930,50 @@ gfxFont::GetShapedWord(gfxContext *aCont
 {
     // if there's a cached entry for this word, just return it
     CacheHashKey key(aText, aLength, aHash,
                      aRunScript,
                      aAppUnitsPerDevUnit,
                      aFlags);
 
     CacheHashEntry *entry = mWordCache.PutEntry(key);
+    if (!entry) {
+        NS_WARNING("failed to create word cache entry - expect missing text");
+        return nsnull;
+    }
     gfxShapedWord *sw = entry->mShapedWord;
     Telemetry::Accumulate(Telemetry::WORD_CACHE_LOOKUP_LEN, aLength);
     Telemetry::Accumulate(Telemetry::WORD_CACHE_LOOKUP_SCRIPT, aRunScript);
 
     if (sw) {
         sw->ResetAge();
         Telemetry::Accumulate(Telemetry::WORD_CACHE_HIT_LEN, aLength);
         Telemetry::Accumulate(Telemetry::WORD_CACHE_HIT_SCRIPT, aRunScript);
         return sw;
     }
 
     sw = entry->mShapedWord = gfxShapedWord::Create(aText, aLength,
                                                     aRunScript,
                                                     aAppUnitsPerDevUnit,
                                                     aFlags);
-    NS_ASSERTION(sw != nsnull,
-                 "failed to create gfxShapedWord - expect missing text");
     if (!sw) {
+        NS_WARNING("failed to create gfxShapedWord - expect missing text");
         return nsnull;
     }
 
-    bool ok;
+    bool ok = false;
     if (sizeof(T) == sizeof(PRUnichar)) {
         ok = ShapeWord(aContext, sw, (const PRUnichar*)aText);
     } else {
         nsAutoString utf16;
         AppendASCIItoUTF16(nsDependentCSubstring((const char*)aText, aLength),
                            utf16);
-        ok = ShapeWord(aContext, sw, utf16.BeginReading());
+        if (utf16.Length() == aLength) {
+            ok = ShapeWord(aContext, sw, utf16.BeginReading());
+        }
     }
     NS_WARN_IF_FALSE(ok, "failed to shape word - expect garbled text");
 
     for (PRUint32 i = 0; i < aLength; ++i) {
         if (aText[i] == ' ') {
             sw->SetIsSpace(i);
         } else if (i > 0 &&
                    NS_IS_HIGH_SURROGATE(aText[i - 1]) &&