Skip to content

Commit

Permalink
MSVC build fix following r211749
Browse files Browse the repository at this point in the history
Avoid strndup()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211752 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
atoker committed Jun 26, 2014
1 parent f93fe90 commit 45f1660
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/Analysis/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
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());
}

return Result;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void LLVMShutdown() {

/*===-- 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) {
Expand Down Expand Up @@ -118,7 +118,7 @@ char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
string_ostream Msg;
DiagnosticPrinterRawOStream DP(Msg);
unwrap(DI)->print(DP);
return LLVMCreateMessage(Msg.str());
return LLVMCreateMessage(Msg);
}

LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
Expand Down Expand Up @@ -204,7 +204,7 @@ LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
char *LLVMPrintModuleToString(LLVMModuleRef M) {
string_ostream os;
unwrap(M)->print(os, nullptr);
return LLVMCreateMessage(os.str());
return LLVMCreateMessage(os);
}

/*--.. Operations on inline assembler ......................................--*/
Expand Down Expand Up @@ -282,7 +282,7 @@ char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
else
os << "Printing <null> Type";

return strndup(os.str().data(), os.str().size());
return LLVMCreateMessage(os);
}

/*--.. Operations on integer types .........................................--*/
Expand Down Expand Up @@ -533,7 +533,7 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
else
os << "Printing <null> Value";

return strndup(os.str().data(), os.str().size());
return LLVMCreateMessage(os);
}

void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
Expand Down
3 changes: 2 additions & 1 deletion lib/IRReader/IRReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
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());
}
return 1;
}
Expand Down

0 comments on commit 45f1660

Please sign in to comment.