Skip to content

Unreachable code in CommandXlat #2768

@xezon

Description

@xezon
		else if( command && (command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_CONSTRUCT
						 || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT) )
		{
			//We're using the build placement interface to determine where to build our special power item.
			//Because of that, we only care about DO_COMMAND. The context evaluation and hint feedback system
			//is already taken care of. But what we need to do is trigger the special power to actually build
			//the object and reset the timer.
			if( type == DO_COMMAND )
			{
				switch( command->getCommandType() )
				{
					case GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT:
					{
						Object* unit = ThePlayerList->getLocalPlayer()->findMostReadyShortcutSpecialPowerOfType( command->getSpecialPowerTemplate()->getSpecialPowerType() );
						if( unit )
							msgType = issueSpecialPowerCommand( command, type, draw, pos, unit );
						break;
					}
					case GUI_COMMAND_SPECIAL_POWER://lorenzen
						msgType = issueSpecialPowerCommand( command, type, draw, pos, nullptr );
						break;
				}
			}
		}

The outer else if only enters this block when commandType is GUI_COMMAND_SPECIAL_POWER_CONSTRUCT or GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT, but the inner switch tests the same value against GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT and GUI_COMMAND_SPECIAL_POWER — entirely different enum values. No case will ever match, so issueSpecialPowerCommand is never called and the command silently does nothing. The case labels should be GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT and GUI_COMMAND_SPECIAL_POWER_CONSTRUCT respectively. Note: the identical pattern exists in GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp (line 1799), so the same bug is present in the Zero Hour build as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is not working right, typically is user facingInvestigate

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions