about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-12-01 15:21:11 +0000
committerbors <bors@rust-lang.org>2016-12-01 15:21:11 +0000
commit908dba0c9477b7dd022a236cb1514ddfca9369f2 (patch)
treea616d31780537a8a3d6bf2e9fcd027bcf8d7ebcf /src/rustllvm/PassWrapper.cpp
parent149e76f12cea86338785050165b65965b1b524a9 (diff)
parent85dc08e525622365909cdaae27f4b89179321a92 (diff)
downloadrust-908dba0c9477b7dd022a236cb1514ddfca9369f2.tar.gz
rust-908dba0c9477b7dd022a236cb1514ddfca9369f2.zip
Auto merge of #38048 - rkruppe:llvm-stringref-fixes, r=alexcrichton
[LLVM 4.0] 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.

cc #37609
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
-rw-r--r--src/rustllvm/PassWrapper.cpp8
1 files changed, 5 insertions, 3 deletions
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()) {