Problem 1148 - std::string being passed to system() instead of std::string::c_str()
Summary: std::string being passed to system() instead of std::string::c_str()
Status: RESOLVED INVALID
Alias: None
Product: Geant4
Classification: Unclassified
Component: run (show other problems)
Version: 9.3
Hardware: All Linux
: P3 normal
Assignee: asai
URL: http://hypernews.slac.stanford.edu/Hy...
Depends on:
Blocks:
 
Reported: 2010-10-12 06:26 CEST by Michael Kelsey
Modified: 2010-10-14 22:58 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
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().