jkorous added a comment.

I tried to come up with some input that breaks current implementation so I 
could add the test. Problem is that invalid memory read doesn't guarantee 
deterministic crash.  
E. g. with this input the current implementation is definitely reading way past 
the buffer:

  SmallVector<char, 1> IgnoreMe;
  const char* Foo = "foo%";
  const char* FooEnd = Foo + 4;
  Diag.FormatDiagnostic(Foo, FooEnd, IgnoreMe);

...and it actually found some string there yet it didn't crash until it hit 
some unrelated assert

  (lldb) p DiagStr
  (const char *) $0 = 0x0000000100adc53b " SplatSizeInBits == 0 && 
\"SplatSizeInBits must divide width!\""
  (lldb) p *DiagStr
  (const char) $1 = ' '
  (lldb) p DiagEnd
  (const char *) $2 = 0x0000000100ad4155 "0"

The only reliable fail is passing nullptr which currently leads to SIGABRT 
(nullptr dereferenced)

  SmallVector<char, 1> IgnoreMe;
  const char* Foo = "foo";
  Diag.FormatDiagnostic(Foo, nullptr, IgnoreMe);

I am reconsidering the necessity of such tests here. WDYT?


Repository:
  rC Clang

https://reviews.llvm.org/D51867



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to