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/PassWrapper.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/rustllvm/PassWrapper.cpp') diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 9230c639833..d1eb261abd3 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -530,9 +530,11 @@ LLVMRustPrintPasses() { struct MyListener : PassRegistrationListener { void passEnumerate(const PassInfo *info) { #if LLVM_VERSION_GE(4, 0) - if (!info->getPassArgument().empty()) { - printf("%15s - %s\n", info->getPassArgument().data(), - info->getPassName().data()); + StringRef PassArg = info->getPassArgument(); + StringRef PassName = info->getPassName(); + if (!PassArg.empty()) { + printf("%15.*s - %.*s\n", PassArg.size(), PassArg.data(), + PassName.size(), PassName.data()); } #else if (info->getPassArgument() && *info->getPassArgument()) { -- cgit 1.4.1-3-g733a5