Skip to content

Commit

Permalink
fix: ensure "no conversion" result is checked correctly
Browse files Browse the repository at this point in the history
Although POSIX said user should check errno instead of return value,
but errno may not be set when no conversion is performed according to C99.
Check nptr is same as str_end to ensure there is no conversion.

Signed-off-by: Celeste Liu <CoelacanthusHex@gmail.com>
  • Loading branch information
CoelacanthusHex committed Aug 19, 2024
1 parent fd58ad7 commit 7b49f45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/applet/notification/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ static int applet_main(int argc, char **argv)
unsigned long seqNumber;

errno = 0;
seqNumber = strtoul(argv[i], NULL, 10);
if (errno != 0)
char *str_end;
seqNumber = strtoul(argv[i], &str_end, 10);
// Although POSIX said user should check errno instead of return value,
// but errno may not be set when no conversion is performed according to C99.
// Check nptr is same as str_end to ensure there is no conversion.
if ((seqNumber == 0 && strcmp(argv[i], str_end)) || errno != 0)
{
continue;
}
Expand Down
8 changes: 6 additions & 2 deletions src/applet/notification/remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ static int applet_main(int argc, char **argv)
unsigned long seqNumber;

errno = 0;
seqNumber = strtoul(argv[i], NULL, 10);
if (errno != 0)
char *str_end;
seqNumber = strtoul(argv[i], &str_end, 10);
// Although POSIX said user should check errno instead of return value,
// but errno may not be set when no conversion is performed according to C99.
// Check nptr is same as str_end to ensure there is no conversion.
if ((seqNumber == 0 && strcmp(argv[i], str_end)) || errno != 0)
{
continue;
}
Expand Down

0 comments on commit 7b49f45

Please sign in to comment.