tailor: fix operator precedence in command parsing

&& has a higher precendence than ||, so this could have resulted in a crash in
some cases. It also produced unintentional behavior where e.g. `tailor 1 foo`
would enable the plugin, unlike `tailor enable foo`.

From #1920
develop
lethosor 2021-09-06 22:32:19 -04:00
parent 4a593a489c
commit a083a7f670
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 6 additions and 3 deletions

@ -33,6 +33,9 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
# Future # Future
## Fixes
- `tailor`: fixed some inconsistencies (and possible crashes) when parsing certain subcommands, e.g. ``tailor help``
# 0.47.05-r3 # 0.47.05-r3
## New Plugins ## New Plugins

@ -571,15 +571,15 @@ DFhackCExport command_result plugin_onupdate(color_ostream& out)
static command_result tailor_cmd(color_ostream& out, vector <string>& parameters) { static command_result tailor_cmd(color_ostream& out, vector <string>& parameters) {
bool desired = enabled; bool desired = enabled;
if (parameters.size() == 1 && parameters[0] == "enable" || parameters[0] == "on" || parameters[0] == "1") if (parameters.size() == 1 && (parameters[0] == "enable" || parameters[0] == "on" || parameters[0] == "1"))
{ {
desired = true; desired = true;
} }
else if (parameters.size() == 1 && parameters[0] == "disable" || parameters[0] == "off" || parameters[0] == "0") else if (parameters.size() == 1 && (parameters[0] == "disable" || parameters[0] == "off" || parameters[0] == "0"))
{ {
desired = false; desired = false;
} }
else if (parameters.size() == 1 && parameters[0] == "usage" || parameters[0] == "help" || parameters[0] == "?") else if (parameters.size() == 1 && (parameters[0] == "usage" || parameters[0] == "help" || parameters[0] == "?"))
{ {
out.print("%s: %s\nUsage:\n%s", plugin_name, tagline, usage); out.print("%s: %s\nUsage:\n%s", plugin_name, tagline, usage);
return CR_OK; return CR_OK;