[LTP] [PATCH] lib/tst_timer_test.c: fix unsigned int overflow on RHEL5.11GA

Cyril Hrubis chrubis@suse.cz
Thu Jul 20 11:13:59 CEST 2017


Hi!
> It sounds better, but this change leads that samples[0] could not be 
> checked if the whole samples array
> is less than usec.
> 
> Could we fix this issue as below:
> ------------------------------------------------------------------------------------------------------------------------
> -    for (i = nsamples - 1; samples[i] < usec; i--);
> +    for (i = nsamples - 1; samples[i] < usec && i > 0; i--);
> 
>       if (i < nsamples - 1) {
> -        tst_res(TFAIL, "%s woken up early %u times range: [%lli,%lli]",
> -            scall, nsamples - 1 - i,
> -            samples[i+1], samples[nsamples-1]);
> +        if (i == 0 && samples[i] < usec) {
> +            tst_res(TFAIL, "%s woken up early %u times range: [%lli,%lli]",
> +                scall, nsamples - i, samples[i],
> +                samples[nsamples-1]);
> +        } else {
> +            tst_res(TFAIL, "%s woken up early %u times range: [%lli,%lli]",
> +                scall, nsamples - 1 - i, samples[i+1],
> +                samples[nsamples-1]);
> +        }
> ------------------------------------------------------------------------------------------------------------------------

That is still unnecessarily complex. I do not care that much about this
corner case, but if we want to fix it correctly we can simply change the
i to be signed integer and check for i > -1 in the loop and everything
would work fine.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list