Problem 1180

Summary: Missing type casts to G4String in several places of G4VBasicShell::ApplyShellCommand()
Product: Geant4 Reporter: Alexey <alexey.radkov>
Component: interfacesAssignee: Koichi Murakami <Koichi.Murakami>
Status: RESOLVED FIXED    
Severity: trivial CC: Gabriele.Cosmo
Priority: P5    
Version: 9.4   
Hardware: All   
OS: All   

Description Alexey 2011-03-23 17:24:25 CET
What affects: commands with specific content fail with messages like:

Directory <command-without-first-3-chars> is not found.

All commands that contain "ls ", "cd " and "help " will fail.

How it is reproducible: create any new command that can contain "ls ", for example boolean command "/myapp/set/crystals". Let the argument be omittable. Then when you type:

/myapp/set/crystals

your command will work well. But if the argument explicitly specified:

/myapp/set/crystals true

the command will fail with that "Directory..." message.

What is wrong: ApplyShellCommand() has lines like:

} else if( command == "ls" || command(0,3) == "ls " ) {
} else if( command == "cd" || command(0,3) == "cd ") {
} else if( command == "help" || command(0,5) == "help ") {

G4String::operator()(str_size, str_size) returns a new object of type G4SubString, and then the G4SubString::operator==() is called with arguments "ls ", "cd " and "help ". These operators look for the match along all the line like "/myapp/set/crystals true" and eventually find it. This is not what was intended.
To fix the problem those G4SubString objects must be preliminary cast to G4String:

} else if( command == "ls" || (G4String)command(0,3) == "ls " ) {
} else if( command == "cd" || (G4String)command(0,3) == "cd ") {
} else if( command == "help" || (G4String)command(0,5) == "help ") {

in which case commands that contain somewhere in the middle "ls ", "cd " and "help " won't be mistakenly supposed as commands ls, cd or help.
Comment 1 Gabriele Cosmo 2011-03-24 09:18:20 CET
The fix is now introduced in tag "interfaces-V09-04-01" which will be available in the next development release and future patches.