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.
This commit is contained in:
Eliseo Martínez 2015-01-12 11:26:13 +01:00
parent 9b4f6fbd33
commit 12f606a2a8

View File

@ -14,6 +14,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h>
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
@ -726,8 +727,7 @@ void ex_hardcopy(exarg_T *eap)
if (got_int || settings.user_abort) if (got_int || settings.user_abort)
goto print_fail; goto print_fail;
assert(prtpos.bytes_printed == 0 assert(prtpos.bytes_printed <= SIZE_MAX / 100);
|| prtpos.bytes_printed * 100 > prtpos.bytes_printed);
sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), sprintf((char *)IObuff, _("Printing page %d (%zu%%)"),
page_count + 1 + side, page_count + 1 + side,
prtpos.bytes_printed * 100 / bytes_to_print); prtpos.bytes_printed * 100 / bytes_to_print);