summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorkhei4 <kk.asano.luxy@gmail.com>2023-07-19 17:00:06 +0900
committerkhei4 <kk.asano.luxy@gmail.com>2023-07-20 16:53:06 +0900
commitc7bf20dfdcbedbba05445035bcabd4f706ba9e42 (patch)
treef0fe6b48db91816d00cd54bd0428d1cfcc671eae /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent4d307c482271ea3575a13b6c04222911e7706189 (diff)
downloadrust-c7bf20dfdcbedbba05445035bcabd4f706ba9e42.tar.gz
rust-c7bf20dfdcbedbba05445035bcabd4f706ba9e42.zip
address feedback from nikic and oli-obk https://github.com/rust-lang/rust/pull/113723/files
use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index 695b8847a97..870a2e02cba 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -112,23 +112,25 @@ extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
   unwrap(M)->setTargetTriple(Triple::normalize(Triple));
 }
 
-extern "C" const char *LLVMRustPrintPassTimings(void) {
+extern "C" const char *LLVMRustPrintPassTimings(size_t *Len) {
   std::string buf;
   raw_string_ostream SS(buf);
   TimerGroup::printAll(SS);
   SS.flush();
-  char* CStr = (char*) malloc((buf.length() + 1) * sizeof(char));
-  strcpy(CStr, buf.c_str());
+  *Len = buf.length();
+  char *CStr = (char *)malloc(*Len);
+  memcpy(CStr, buf.c_str(), *Len);
   return CStr;
 }
 
-extern "C" const char *LLVMRustPrintStatistics(void) {
+extern "C" const char *LLVMRustPrintStatistics(size_t *Len) {
   std::string buf;
   raw_string_ostream SS(buf);
   llvm::PrintStatistics(SS);
   SS.flush();
-  char* CStr = (char*) malloc((buf.length() + 1) * sizeof(char));
-  strcpy(CStr, buf.c_str());
+  *Len = buf.length();
+  char *CStr = (char *)malloc(*Len);
+  memcpy(CStr, buf.c_str(), *Len);
   return CStr;
 }