Re: [PATCH] fix potential infinite loop given large unsigned integer
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Aug 10, 2009, 16:53 UTC
- Message-ID
- <alpine.DEB.1.00.0908101850570.8324@intel-tinevez-2-302>
- In-Reply-To
- <a3f15ee60908100917k2a2d6de7ndd5e4ddd1d926cc3@mail.gmail.com>
Hi,
[please cull the quoted text to what you are actually replying to. Thanks]
On Mon, 10 Aug 2009, Ryan Flynn wrote:
Show 11 quoted lines
> On Mon, Aug 10, 2009 at 8:24 AM, Johannes
> Schindelin<Johannes.Schindelin@gmx.de> wrote:
> >
> > static unsigned int digits_of_number(unsigned int number) {
> > unsigned int result;
> > for (result = 1; number; number /= 10, result++)
> > ; /* do nothing */
> > return result;
> > }
>
> whoops, actually yours: digits_of_number(1) -> 2static unsigned int digits(unsigned int number)
{
unsigned int result;
for (result = 1; (number /= 10); result++)
; /* do nothing */
return result;
}I'm sorry, I forgot the "something like this" in my mail.
This version is actually tested.
It has non-optimal runtime, but then, it does not really matter.
Ciao, Dscho