Avoid strndup()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211752
91177308-0d34-0410-b5e6-
96231b3b80d8
if (Action == LLVMAbortProcessAction && Result)
report_fatal_error("Broken module found, compilation aborted!");
if (Action == LLVMAbortProcessAction && Result)
report_fatal_error("Broken module found, compilation aborted!");
- if (OutMessages)
- *OutMessages = strndup(MsgsOS.str().data(), MsgsOS.str().size());
+ if (OutMessages) {
+ MsgsOS << '\0';
+ *OutMessages = strdup(MsgsOS.str().data());
+ }
/*===-- Error handling ----------------------------------------------------===*/
/*===-- Error handling ----------------------------------------------------===*/
-static char *LLVMCreateMessage(StringRef Message) {
- assert(Message.find('\0') == Message.npos);
- return strndup(Message.data(), Message.size());
+static char *LLVMCreateMessage(string_ostream &OS) {
+ OS << '\0';
+ return strdup(OS.str().data());
}
char *LLVMCreateMessage(const char *Message) {
}
char *LLVMCreateMessage(const char *Message) {
string_ostream Msg;
DiagnosticPrinterRawOStream DP(Msg);
unwrap(DI)->print(DP);
string_ostream Msg;
DiagnosticPrinterRawOStream DP(Msg);
unwrap(DI)->print(DP);
- return LLVMCreateMessage(Msg.str());
+ return LLVMCreateMessage(Msg);
}
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
}
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
char *LLVMPrintModuleToString(LLVMModuleRef M) {
string_ostream os;
unwrap(M)->print(os, nullptr);
char *LLVMPrintModuleToString(LLVMModuleRef M) {
string_ostream os;
unwrap(M)->print(os, nullptr);
- return LLVMCreateMessage(os.str());
+ return LLVMCreateMessage(os);
}
/*--.. Operations on inline assembler ......................................--*/
}
/*--.. Operations on inline assembler ......................................--*/
else
os << "Printing <null> Type";
else
os << "Printing <null> Type";
- return strndup(os.str().data(), os.str().size());
+ return LLVMCreateMessage(os);
}
/*--.. Operations on integer types .........................................--*/
}
/*--.. Operations on integer types .........................................--*/
else
os << "Printing <null> Value";
else
os << "Printing <null> Value";
- return strndup(os.str().data(), os.str().size());
+ return LLVMCreateMessage(os);
}
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
}
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
if (OutMessage) {
string_ostream os;
Diag.print(nullptr, os, false);
if (OutMessage) {
string_ostream os;
Diag.print(nullptr, os, false);
- *OutMessage = strndup(os.str().data(), os.str().size());
+ os << '\0';
+ *OutMessage = strdup(os.str().data());