Problem 1148

Summary: std::string being passed to system() instead of std::string::c_str()
Product: Geant4 Reporter: Michael Kelsey <kelsey>
Component: runAssignee: asai
Status: RESOLVED INVALID    
Severity: normal    
Priority: P3    
Version: 9.3   
Hardware: All   
OS: Linux   
URL: http://hypernews.slac.stanford.edu/HyperNews/geant4/get/runmanage/286.html

Description Michael Kelsey 2010-10-12 06:26:51 CEST
In G4RunManager.hh, the function

    inline void SetRandomNumberStoreDir(const G4String& dir)
    { 
      G4String dirStr = dir;
      if( dirStr(dirStr.length()-1) != '/' ) dirStr += "/";
#ifndef WIN32
      G4String shellCmd = "mkdir -p ";
#else
      std::replace(dirStr.begin(), dirStr.end(),'/','\\');
      G4String shellCmd = "mkdir ";
#endif
      shellCmd += dirStr;
      randomNumberStatusDir = dirStr;
      system(shellCmd); 
    }

Should have the last line written "system(shellCmd.c_str());" to conform to the calling convention system(const char*).  The current code produces a warning on some Linux flavors (technically, some GCC versions).
Comment 1 Michael Kelsey 2010-10-14 22:58:07 CEST
In fact, this isn't a bug.  G4String inherits from std::string, but adds numerous additional interfaces, including an automatic conversion to const char*.  This conversion satisfies the signature of system().