[LLVMdev] dodgy use of c_str()

Jay Foad jay.foad at gmail.com
Fri Nov 13 05:07:36 PST 2009


>From llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp:

void DebugInfo::EmitGlobalVariable(GlobalVariable *GV, tree decl) {
  // Gather location information.
  expanded_location Loc = expand_location(DECL_SOURCE_LOCATION(decl));
  DIType TyD = getOrCreateType(TREE_TYPE(decl));
  const char *DispName = GV->getNameStr().c_str();

Isn't this use of c_str() dodgy, because the temporary string returned
by Gv->getNameStr() will be destroyed at the end of the expression, so
it's no longer valid to use the memory pointed to by DispName?

Thanks,
Jay.



More information about the llvm-dev mailing list