]> granicus.if.org Git - clang/commitdiff
Don't crash when trying to emit too many fixits. Also, keep some constants in
authorMatt Beaumont-Gay <matthewbg@google.com>
Mon, 3 Oct 2011 16:26:56 +0000 (16:26 +0000)
committerMatt Beaumont-Gay <matthewbg@google.com>
Mon, 3 Oct 2011 16:26:56 +0000 (16:26 +0000)
sync between DiagnosticsEngine and PartialDiagnostic.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141006 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
include/clang/Basic/PartialDiagnostic.h

index 492c8b069e1ca12523f33fe63e0a1091ff8369e6..fefc44ce7bc6e1ce6b2c3343c54aac52423c76af 100644 (file)
@@ -778,6 +778,8 @@ public:
   void AddFixItHint(const FixItHint &Hint) const {
     assert(NumFixItHints < DiagnosticsEngine::MaxFixItHints &&
            "Too many fix-it hints!");
+    if (NumFixItHints >= DiagnosticsEngine::MaxFixItHints)
+      return;  // Don't crash in release builds
     if (DiagObj)
       DiagObj->FixItHints[NumFixItHints++] = Hint;
   }
index 4eff3a188e0420d01b617f5028aec4a3efe8ea62..c6ca98976555baf1af5688ef4dd936d1c04938b5 100644 (file)
@@ -33,7 +33,7 @@ public:
         /// currently only support up to 10 arguments (%0-%9).
         /// A single diagnostic with more than that almost certainly has to
         /// be simplified anyway.
-        MaxArguments = 10
+        MaxArguments = DiagnosticsEngine::MaxArguments
     };
   
     /// NumDiagArgs - This contains the number of entries in Arguments.
@@ -65,7 +65,7 @@ public:
     /// only support 10 ranges, could easily be extended if needed.
     CharSourceRange DiagRanges[10];
     
-    enum { MaxFixItHints = 3 };
+    enum { MaxFixItHints = DiagnosticsEngine::MaxFixItHints };
     
     /// FixItHints - If valid, provides a hint with some code
     /// to insert, remove, or modify at a particular position.
@@ -165,6 +165,8 @@ private:
 
     assert(DiagStorage->NumFixItHints < Storage::MaxFixItHints &&
            "Too many code modification hints!");
+    if (DiagStorage->NumFixItHints >= Storage::MaxFixItHints)
+      return;  // Don't crash in release builds
     DiagStorage->FixItHints[DiagStorage->NumFixItHints++]
       = Hint;
   }