diff options
| author | Robin Kruppe <robin.kruppe@gmail.com> | 2016-11-28 15:15:51 +0100 |
|---|---|---|
| committer | Robin Kruppe <robin.kruppe@gmail.com> | 2016-11-28 17:33:13 +0100 |
| commit | 85dc08e525622365909cdaae27f4b89179321a92 (patch) | |
| tree | 4bbe8a467e191e43c0f1c5a8d30be304a6a6c045 /src/rustllvm/RustWrapper.cpp | |
| parent | c7ddb8946bf041d89ba109ec8dd754492de78606 (diff) | |
| download | rust-85dc08e525622365909cdaae27f4b89179321a92.tar.gz rust-85dc08e525622365909cdaae27f4b89179321a92.zip | |
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.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 9f0e38b53ff..818737dfe7c 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -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 |
