From 12f606a2a8e8a61c9f54ce87ed680914eaa503fe Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 12 Jan 2015 11:26:13 +0100 Subject: Fix bad assert. Problem : Assert can fail for legal values. Modulo-arithmetic of unsigned types can make so that n * 100 > n, but n has overflowed. Solution : Use alternative form of expression. --- src/nvim/hardcopy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 993ec143bb..92abcbada4 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "nvim/vim.h" #include "nvim/ascii.h" @@ -726,8 +727,7 @@ void ex_hardcopy(exarg_T *eap) if (got_int || settings.user_abort) goto print_fail; - assert(prtpos.bytes_printed == 0 - || prtpos.bytes_printed * 100 > prtpos.bytes_printed); + assert(prtpos.bytes_printed <= SIZE_MAX / 100); sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), page_count + 1 + side, prtpos.bytes_printed * 100 / bytes_to_print); -- cgit From 634d5d86a7cb249ca62795be06a6615705bdfb0b Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 12 Jan 2015 11:46:19 +0100 Subject: coverity/100248: Operands don't affect result: HI. Problem : Operands don't affect results (CONSTANT_EXPRESSION_RESULT). Diagnostic : Harmless issue. Rationale : n >= LONG_MIN, n being intmax_t, is always true for architectures where sizeof(intmax_t) == sizeof(long). Resolution : Add sizes check. --- src/nvim/charset.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 8781e389ed..7356d91ac2 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1695,7 +1695,9 @@ intmax_t getdigits(char_u **pp) int getdigits_int(char_u **pp) { intmax_t number = getdigits(pp); +#if SIZEOF_INTMAX_T > SIZEOF_INT assert(number >= INT_MIN && number <= INT_MAX); +#endif return (int)number; } @@ -1705,7 +1707,9 @@ int getdigits_int(char_u **pp) long getdigits_long(char_u **pp) { intmax_t number = getdigits(pp); +#if SIZEOF_INTMAX_T > SIZEOF_LONG assert(number >= LONG_MIN && number <= LONG_MAX); +#endif return (long)number; } -- cgit