From 6722b2d8c422493829c4c57ca5ec1919c7c74231 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Tue, 9 Jun 2020 07:56:17 +0300 Subject: [PATCH] core-util: Make range checks easier to read It wasn't immediately obvious to me what these checks are supposed to do. Explicitly checking against the min/max values should make the code easier to understand. Part-of: --- src/pulsecore/core-util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index d421a75..a6473c1 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2189,7 +2189,7 @@ int pa_atoi(const char *s, int32_t *ret_i) { if (pa_atol(s, &l) < 0) return -1; - if ((int32_t) l != l) { + if (l < INT32_MIN || l > INT32_MAX) { errno = ERANGE; return -1; } @@ -2233,7 +2233,7 @@ int pa_atou(const char *s, uint32_t *ret_u) { return -1; } - if ((uint32_t) l != l) { + if (l > UINT32_MAX) { errno = ERANGE; return -1; } @@ -2277,7 +2277,7 @@ int pa_atou64(const char *s, uint64_t *ret_u) { return -1; } - if ((uint64_t) l != l) { + if (l > UINT64_MAX) { errno = ERANGE; return -1; } @@ -2360,7 +2360,7 @@ int pa_atoi64(const char *s, int64_t *ret_l) { *ret_l = l; - if ((int64_t) l != l) { + if (l < INT64_MIN || l > INT64_MAX) { errno = ERANGE; return -1; } -- 2.7.4