Fixed a bug regarding lifetime of C strings.

The string returned by c_str() is only valid as long as the object exists. Now the object 'triple' exists until the end.
This commit is contained in:
kai 2012-08-28 06:52:29 +02:00
parent 7c7a9e564a
commit af69672dc7

View file

@ -477,6 +477,8 @@ int main(int argc, char** argv)
#endif
}
std::string triple;
// did the user override the target triple?
if (mTargetTriple.empty())
{
@ -485,14 +487,14 @@ int main(int argc, char** argv)
error("you must specify a target triple as well with -mtriple when using the -march option");
fatal();
}
global.params.targetTriple = defaultTriple.c_str();
triple = defaultTriple;
}
else
{
global.params.targetTriple = llvm::Triple::normalize(mTargetTriple).c_str();
triple = llvm::Triple::normalize(mTargetTriple);
}
std::string triple = global.params.targetTriple;
global.params.targetTriple = triple.c_str();
// Allocate target machine.
const llvm::Target *theTarget = NULL;