diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-11-22 23:07:02 (GMT) |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-11-22 23:07:02 (GMT) |
commit | 1b06060cbcc4bf637fcdbfec181d738f01dfed46 (patch) | |
tree | 87248a466dee9653491828c5e012959a427207cd /plugins | |
parent | f054ab04e788405932b9bb081747bc7c8328a0d8 (diff) | |
download | monitoring-plugins-1b06060cbcc4bf637fcdbfec181d738f01dfed46.tar.gz |
Fix logic in is_uint64_t to fix type-limit warning
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/utils.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index e871c5f..aff1790 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -258,16 +258,25 @@ bool is_int64(char *number, int64_t *target) { | |||
258 | */ | 258 | */ |
259 | bool is_uint64(char *number, uint64_t *target) { | 259 | bool is_uint64(char *number, uint64_t *target) { |
260 | errno = 0; | 260 | errno = 0; |
261 | uint64_t tmp = strtoll(number, NULL, 10); | 261 | char *endptr = { 0 }; |
262 | unsigned long long tmp = strtoull(number, &endptr, 10); | ||
263 | |||
262 | if (errno != 0) { | 264 | if (errno != 0) { |
263 | return false; | 265 | return false; |
264 | } | 266 | } |
265 | if (tmp < 0 || tmp > UINT64_MAX) { | 267 | |
268 | if (*endptr != '\0') { | ||
266 | return false; | 269 | return false; |
267 | } | 270 | } |
271 | |||
272 | if (tmp > UINT64_MAX) { | ||
273 | return false; | ||
274 | } | ||
275 | |||
268 | if (target != NULL) { | 276 | if (target != NULL) { |
269 | *target = tmp; | 277 | *target = (uint64_t)tmp; |
270 | } | 278 | } |
279 | |||
271 | return true; | 280 | return true; |
272 | } | 281 | } |
273 | 282 | ||