{"thread":{"id":"37976","subject":"[PATCH] use labs() for variables of type long instead of abs()","startedAt":"2014-11-15T13:27:21Z","lastAt":"2014-11-15T13:27:21Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"251942","messageId":"546754B9.2080305@web.de","threadId":"37976","inReplyTo":null,"subject":"[PATCH] use labs() for variables of type long instead of abs()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-11-15T13:27:21Z","receivedAt":"2014-11-15T13:27:21Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Using abs() on long values can cause truncation, so use labs() instead.\nReported by Clang 3.5 (-Wabsolute-value, enabled by -Wall).\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/receive-pack.c | 2 +-\n config.c               | 4 ++--\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 32fc540..e908d07 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -431,7 +431,7 @@ static const char *check_nonce(const char *buf, size_t len)\n \tnonce_stamp_slop = (long)ostamp - (long)stamp;\n \n \tif (nonce_stamp_slop_limit &&\n-\t    abs(nonce_stamp_slop) <= nonce_stamp_slop_limit) {\n+\t    labs(nonce_stamp_slop) <= nonce_stamp_slop_limit) {\n \t\t/*\n \t\t * Pretend as if the received nonce (which passes the\n \t\t * HMAC check, so it is not a forged by third-party)\ndiff --git a/config.c b/config.c\nindex 15a2983..ae1398f 100644\n--- a/config.c\n+++ b/config.c\n@@ -506,9 +506,9 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)\n \t\t\terrno = EINVAL;\n \t\t\treturn 0;\n \t\t}\n-\t\tuval = abs(val);\n+\t\tuval = labs(val);\n \t\tuval *= factor;\n-\t\tif (uval > max || abs(val) > uval) {\n+\t\tif (uval > max || labs(val) > uval) {\n \t\t\terrno = ERANGE;\n \t\t\treturn 0;\n \t\t}\n-- \n2.1.3\n"}]}