-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Robin Kruppe
committed
Nov 28, 2016
1 parent
c7ddb89
commit 85dc08e
Showing
5 changed files
with
26 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
hanna-kruppe
Contributor
|
||
PassName.size(), PassName.data()); | ||
} | ||
#else | ||
if (info->getPassArgument() && *info->getPassArgument()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rkruppe
Any concern?