[Mesa-dev] [PATCH 3/4] gallium/hud: prevent an infinite loop
Marek Olšák
maraeo at gmail.com
Mon Feb 20 17:44:44 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/hud/hud_context.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index aaa52d5..488fe66 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -724,23 +724,23 @@ hud_pane_set_max_value(struct hud_pane *pane, uint64_t value)
uint64_t exp10;
int i;
/* The following code determines the max_value in the graph as well as
* how many describing lines are drawn. The max_value is rounded up,
* so that all drawn numbers are rounded for readability.
* We want to print multiples of a simple number instead of multiples of
* hard-to-read numbers like 1.753.
*/
- /* Find the left-most digit. */
+ /* Find the left-most digit. Make sure exp10 * 9 doesn't overflow. */
exp10 = 1;
- for (i = 0; value > 9 * exp10; i++) {
+ for (i = 0; exp10 <= UINT64_MAX / 9 && exp10 * 9 < value; i++) {
exp10 *= 10;
fixup_bytes(pane->type, i + 1, &exp10);
}
leftmost_digit = DIV_ROUND_UP(value, exp10);
/* Round 9 to 10. */
if (leftmost_digit == 9) {
leftmost_digit = 1;
exp10 *= 10;
--
2.7.4
More information about the mesa-dev
mailing list