Bug 1074809 - For OTS warning (rather than failure) messages, only log the first occurrence of any given message per font. r=jdaggett
authorJonathan Kew <jkew@mozilla.com>
Fri, 10 Oct 2014 14:50:52 +0100
changeset 209856 0402daa909e416b596ddac2980e916907ed27205
parent 209855 e0662f559c632a79ce1021e0eada0953590d14ce
child 209857 0fbe7cd05a11269bcdd7e43da91ff16994fd97ff
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjdaggett
bugs1074809
milestone35.0a1
Bug 1074809 - For OTS warning (rather than failure) messages, only log the first occurrence of any given message per font. r=jdaggett
gfx/thebes/gfxUserFontSet.cpp
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -194,28 +194,36 @@ public:
         return ots::TABLE_ACTION_DEFAULT;
     }
 
     virtual void Message(int level, const char* format,
                          ...) MSGFUNC_FMT_ATTR MOZ_OVERRIDE {
         va_list va;
         va_start(va, format);
 
-        // buf should be more than adequate for any message OTS generates,
-        // so we don't worry about checking the result of vsnprintf()
-        char buf[512];
-        (void)vsnprintf(buf, sizeof(buf), format, va);
+        nsCString msg;
+        msg.AppendPrintf(format, va);
 
         va_end(va);
 
-        mUserFontEntry->mFontSet->LogMessage(mUserFontEntry, buf);
+        if (level > 0) {
+            // For warnings (rather than errors that cause the font to fail),
+            // we only report the first instance of any given message.
+            if (mWarningsIssued.Contains(msg)) {
+                return;
+            }
+            mWarningsIssued.PutEntry(msg);
+        }
+
+        mUserFontEntry->mFontSet->LogMessage(mUserFontEntry, msg.get());
     }
 
 private:
     gfxUserFontEntry* mUserFontEntry;
+    nsTHashtable<nsCStringHashKey> mWarningsIssued;
 };
 
 // Call the OTS library to sanitize an sfnt before attempting to use it.
 // Returns a newly-allocated block, or nullptr in case of fatal errors.
 const uint8_t*
 gfxUserFontEntry::SanitizeOpenTypeData(const uint8_t* aData,
                                        uint32_t       aLength,
                                        uint32_t&      aSaneLength,