From 85dc08e525622365909cdaae27f4b89179321a92 Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Mon, 28 Nov 2016 15:15:51 +0100 Subject: 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. --- src/rustllvm/RustWrapper.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/rustllvm/RustWrapper.cpp') 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(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 -- cgit 1.4.1-3-g733a5