mirror of
https://github.com/nilfs-dev/nilfs-utils.git
synced 2026-01-26 13:43:15 +00:00
chcp: fix inverted logic in argument parsing
Since commit 7aae659498b8 ("chcp: fix segfault"), the logic to
distinguish between the optional device argument and the checkpoint
number list has been inverted.
The code intended to check if the current argument is *not* a valid
checkpoint number (indicating it is a device string). However, due to
a logic error in that commit, if the argument is not a number (e.g.
"/dev/sda1"), it sets the device to NULL (implying no device argument).
Conversely, if it is a number, it incorrectly consumes it as a device
name.
This causes chcp to fail with "invalid checkpoint number" when a device
is explicitly specified, because the parser fails to advance past the
device string, subsequently attempting to parse the device name as a
checkpoint number in the main loop.
Fix this regression by correcting the if-else branch assignments.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Fixes: 7aae659498b8 ("chcp: fix segfault")
This commit is contained in:
parent
fd6402a08b
commit
7d363e7430
@ -118,9 +118,9 @@ int main(int argc, char *argv[])
|
||||
modestr = argv[optind++];
|
||||
cno = nilfs_parse_cno(argv[optind], &endptr, CHCP_BASE);
|
||||
if (cno >= NILFS_CNO_MAX || *endptr != '\0')
|
||||
dev = NULL;
|
||||
else
|
||||
dev = argv[optind++];
|
||||
else
|
||||
dev = NULL;
|
||||
}
|
||||
|
||||
if (strcmp(modestr, CHCP_MODE_CP) == 0)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user