Don't assume llvm::StringRef is null terminated
StringRefs have a length and their contents are not usually null-terminated. The solution is to either copy the string data (in rustc_llvm::diagnostic) or take the size into account (in LLVMRustPrintPasses). I couldn't trigger a bug caused by this (apparently all the strings returned in practice are actually null-terminated) but this is more correct and more future-proof.
This commit is contained in:
parent
c7ddb8946b
commit
85dc08e525
5 changed files with 26 additions and 28 deletions
|
@ -872,7 +872,7 @@ LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef str) {
|
|||
extern "C" void
|
||||
LLVMRustUnpackOptimizationDiagnostic(
|
||||
LLVMDiagnosticInfoRef di,
|
||||
const char **pass_name_out,
|
||||
RustStringRef pass_name_out,
|
||||
LLVMValueRef *function_out,
|
||||
LLVMDebugLocRef *debugloc_out,
|
||||
RustStringRef message_out)
|
||||
|
@ -881,15 +881,12 @@ LLVMRustUnpackOptimizationDiagnostic(
|
|||
llvm::DiagnosticInfoOptimizationBase *opt
|
||||
= static_cast<llvm::DiagnosticInfoOptimizationBase*>(unwrap(di));
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
*pass_name_out = opt->getPassName().data();
|
||||
#else
|
||||
*pass_name_out = opt->getPassName();
|
||||
#endif
|
||||
raw_rust_string_ostream pass_name_os(pass_name_out);
|
||||
pass_name_os << opt->getPassName();
|
||||
*function_out = wrap(&opt->getFunction());
|
||||
*debugloc_out = wrap(&opt->getDebugLoc());
|
||||
raw_rust_string_ostream os(message_out);
|
||||
os << opt->getMsg();
|
||||
raw_rust_string_ostream message_os(message_out);
|
||||
message_os << opt->getMsg();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue