Merge pull request #58 from lioncash/overrun2

ControlMapper: Prevent array overrun cases
This commit is contained in:
Phillip Stephens 2019-09-06 23:18:32 -07:00 committed by GitHub
commit 58fa527aeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 14 deletions

View File

@ -7,18 +7,29 @@
namespace urde { namespace urde {
static const char* skCommandDescs[] = { static const char* skCommandDescs[] = {
"Forward", "Backward", "Turn Left", "Turn Right", "Strafe Left", "Strafe Right", "Forward", "Backward", "Turn Left",
"Look Left", "Look Right", "Look Up", "Look Down", "Jump/Boost", "Fire/Bomb", "Turn Right", "Strafe Left", "Strafe Right",
"Missile/PowerBomb", "Morph", "Aim Up", "Aim Down", "Cycle Beam Up", "Cycle Beam Down", "Look Left", "Look Right", "Look Up",
"Cycle Item", "Power Beam", "Ice Beam", "Wave Beam", "Plasma Beam", "Toggle Holster", "Look Down", "Jump/Boost", "Fire/Bomb",
"Orbit Close", "Orbit Far", "Orbit Object", "Orbit Select", "Orbit Confirm", "Orbit Left", "Missile/PowerBomb", "Morph", "Aim Up",
"Orbit Right", "Orbit Up", "Orbit Down", "Look Hold1", "Look Hold2", "Look Zoom In", "Aim Down", "Cycle Beam Up", "Cycle Beam Down",
"Look Zoom Out", "Aim Hold", "Map Circle Up", "Map Circle Down", "Map Circle Left", "Map Circle Right", "Cycle Item", "Power Beam", "Ice Beam",
"Map Move Forward", "Map Move Back", "Map Move Left", "Map Move Right", "Map Zoom In", "Map Zoom Out", "Wave Beam", "Plasma Beam", "Toggle Holster",
"SpiderBall", "Chase Camera", "XRay Visor", "Thermo Visor", "Enviro Visor", "No Visor", "Orbit Close", "Orbit Far", "Orbit Object",
"Visor Menu", "Visor Up", "Visor Down", "UNKNOWN", "UNKNOWN", "Use Shield", "Orbit Select", "Orbit Confirm", "Orbit Left",
"Scan Item", "UNKNOWN" "Orbit Right", "Orbit Up", "Orbit Down",
"Look Hold1", "Look Hold2", "Look Zoom In",
"Look Zoom Out", "Aim Hold", "Map Circle Up",
"Map Circle Down", "Map Circle Left", "Map Circle Right",
"Map Move Forward", "Map Move Back", "Map Move Left",
"Map Move Right", "Map Zoom In", "Map Zoom Out",
"SpiderBall", "Chase Camera", "XRay Visor",
"Thermo Visor", "Enviro Visor", "No Visor",
"Visor Menu", "Visor Up", "Visor Down",
"UNKNOWN", "UNKNOWN", "Use Shield",
"Scan Item", "UNKNOWN", "UNKNOWN",
"UNKNOWN", "UNKNOWN", "Previous Pause Screen",
"Next Pause Screen", "UNKNOWN", "None",
}; };
static const char* skFunctionDescs[] = {"None", static const char* skFunctionDescs[] = {"None",
@ -359,14 +370,16 @@ float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) {
} }
const char* ControlMapper::GetDescriptionForCommand(ECommands cmd) { const char* ControlMapper::GetDescriptionForCommand(ECommands cmd) {
if (cmd > ECommands::MAX) if (cmd >= ECommands::MAX) {
return nullptr; return nullptr;
}
return skCommandDescs[int(cmd)]; return skCommandDescs[int(cmd)];
} }
const char* ControlMapper::GetDescriptionForFunction(EFunctionList func) { const char* ControlMapper::GetDescriptionForFunction(EFunctionList func) {
if (func > EFunctionList::MAX) if (func >= EFunctionList::MAX) {
return nullptr; return nullptr;
}
return skFunctionDescs[int(func)]; return skFunctionDescs[int(func)];
} }