Module: monitoring-plugins
 Branch: master
 Commit: 1b06060cbcc4bf637fcdbfec181d738f01dfed46
 Author: RincewindsHat <12514511+rincewinds...@users.noreply.github.com>
   Date: Thu Nov 23 00:07:02 2023 +0100
    URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=1b06060

Fix logic in is_uint64_t to fix type-limit warning

---

 plugins/utils.c | 15 ++++++++++++---
 1 file 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) {
  */
 bool is_uint64(char *number, uint64_t *target) {
        errno = 0;
-       uint64_t tmp = strtoll(number, NULL, 10);
+       char *endptr = { 0 };
+       unsigned long long tmp = strtoull(number, &endptr, 10);
+
        if (errno != 0) {
                return false;
        }
-       if (tmp < 0 || tmp > UINT64_MAX) {
+
+       if (*endptr != '\0') {
                return false;
        }
+
+       if (tmp > UINT64_MAX) {
+               return false;
+       }
+
        if (target != NULL) {
-               *target = tmp;
+               *target = (uint64_t)tmp;
        }
+
        return true;
 }
 

Reply via email to