Skip to content

Commit a97e6c1

Browse files
committed
sequencer: stop pretending that an assignment is a condition
In 3e81bcc (sequencer: factor out todo command name parsing, 2019-06-27), a `return` statement was introduced that basically was a long sequence of conditions, combined with `&&`, except for the last condition which is not really a condition but an assignment. The point of this construct was to return 1 (i.e. `true`) from the function if all of those conditions held true, and also assign the `bol` pointer to the end of the parsed command. Some static analyzers are really unhappy about such constructs. And human readers are at least puzzled, if not confused, by seeing a single `=` inside a chain of conditions where they would have expected to see `==` instead and, based on experience, immediately suspect a typo. Let's help all of this by turning this into the more verbose, more readable form of an `if` construct that both assigns the pointer as well as returns 1 if all of the conditions hold true. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4241f0a commit a97e6c1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sequencer.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -2600,9 +2600,12 @@ static int is_command(enum todo_command command, const char **bol)
26002600
const char nick = todo_command_info[command].c;
26012601
const char *p = *bol;
26022602

2603-
return (skip_prefix(p, str, &p) || (nick && *p++ == nick)) &&
2604-
(*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) &&
2605-
(*bol = p);
2603+
if ((skip_prefix(p, str, &p) || (nick && *p++ == nick)) &&
2604+
(*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p)) {
2605+
*bol = p;
2606+
return 1;
2607+
}
2608+
return 0;
26062609
}
26072610

26082611
static int check_label_or_ref_arg(enum todo_command command, const char *arg)

0 commit comments

Comments
 (0)