scp-fs2open / scp-fs2open/fs2open.github.com

Potentially dangerous function parameter in check_control()

Open
#7,088 0 comments 0 reactions 1 assignee Claimed by @z64555 View on GitHub
controls documentation refactor
Dominant language
C++
Stars
487
Forks
184
PR merge metrics
PR metrics pending

Description

```int check_control(int id, int key = -1);```

Parameter `key` is potentially dangerous, since the function contains a static variable that keeps the last value of key passed to it.

Currently, the parameter is responsibly only used by a call within keycontrol.cpp::process_player_keys() and keycontrol.cpp::process_set_of_keys(), both of which are called within game_frame(). There's also calls to check_control() within the lab.

The issue with this parameter is that any usage of it will have following calls use that value later. Updating the documentation to inform potential users of the danger is perhaps the minimal amount of action needed at the moment, but the usage of static variables within functions is still a bad design.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.