From: andy Date: Fri, 11 Mar 2005 21:49:31 +0000 (+0000) Subject: Fix an infinite loop (due to an overflow condition) when printing some X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8ac27cc7980eeb743684532cf255553368672d3a;p=simgear.git Fix an infinite loop (due to an overflow condition) when printing some very large numbers. --- diff --git a/simgear/nasal/string.c b/simgear/nasal/string.c index 6d9434f7..fc0acb04 100644 --- a/simgear/nasal/string.c +++ b/simgear/nasal/string.c @@ -213,13 +213,13 @@ static int tonum(unsigned char* s, int len, double* result) // Very simple positive (!) integer print routine. Puts the result in // s and returns the number of characters written. Does not null -// terminate the result. +// terminate the result. Presumes at least a 32 bit integer, and +// cannot print integers larger than 9999999999. static int decprint(int val, unsigned char* s) { int p=1, i=0; if(val == 0) { *s = '0'; return 1; } - while(p <= val) p *= 10; - p /= 10; + while(p < 1000000000 && p*10 < val) p *= 10; while(p > 0) { int count = 0; while(val >= p) { val -= p; count++; }