1
Fork 0
use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
This commit is contained in:
khei4 2023-07-19 17:00:06 +09:00
parent 4d307c4822
commit c7bf20dfdc
3 changed files with 25 additions and 24 deletions

View file

@ -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;
}