Skip to content

Commit

Permalink
clients/upslog.c: fix max loops CLI arg processing [#2753]
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jan 5, 2025
1 parent 528f835 commit 1d8bf92
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion clients/upslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,28 @@ int main(int argc, char **argv)
break;

case 'd':
str_to_ulong_strict(optarg, &max_loops, 10);
{ /* scoping */
unsigned long ul = 0;
if (str_to_ulong(optarg, &ul, 10)) {
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) )
# pragma GCC diagnostic push
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS
# pragma GCC diagnostic ignored "-Wtype-limits"
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE
# pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#endif
if (ul < SIZE_MAX)
max_loops = (size_t)ul;
else
upslogx(LOG_ERR, "Invalid max loops");
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) )
# pragma GCC diagnostic pop
#endif
} else
upslogx(LOG_ERR, "Invalid max loops");
}
break;

case 'f':
Expand Down

0 comments on commit 1d8bf92

Please sign in to comment.