Problem 1180 - Missing type casts to G4String in several places of G4VBasicShell::ApplyShellCommand()
Summary: Missing type casts to G4String in several places of G4VBasicShell::ApplyShell...
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: interfaces (show other problems)
Version: 9.4
Hardware: All All
: P5 trivial
Assignee: Koichi Murakami
URL:
Depends on:
Blocks:
 
Reported: 2011-03-23 17:24 CET by Alexey
Modified: 2011-03-24 09:18 CET (History)
1 user (show)

See Also:


Attachments

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