Skip to contentSkip to conversation

use labs() for variables of type long instead of abs()

PATCH New René Scharfe 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use labs() for variables of type long instead of abs()

Using abs() on long values can cause truncation, so use labs() instead. Reported by Clang 3.5 (-Wabsolute-value, enabled by -Wall).

---
 builtin/receive-pack.c | 2 +-
 config.c               | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
builtin/receive-pack.c +1 -1
index 32fc540..e908d07 100644
@@ -431,7 +431,7 @@ static const char *check_nonce(const char *buf, size_t len)
 	nonce_stamp_slop = (long)ostamp - (long)stamp;
 
 	if (nonce_stamp_slop_limit &&
-	    abs(nonce_stamp_slop) <= nonce_stamp_slop_limit) {
+	    labs(nonce_stamp_slop) <= nonce_stamp_slop_limit) {
 		/*
 		 * Pretend as if the received nonce (which passes the
 		 * HMAC check, so it is not a forged by third-party)
config.c +2 -2
index 15a2983..ae1398f 100644
@@ -506,9 +506,9 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
 			errno = EINVAL;
 			return 0;
 		}
-		uval = abs(val);
+		uval = labs(val);
 		uval *= factor;
-		if (uval > max || abs(val) > uval) {
+		if (uval > max || labs(val) > uval) {
 			errno = ERANGE;
 			return 0;
 		}
Signature · 1 line
2.1.3