From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cyril Hrubis Date: Thu, 20 Jul 2017 11:13:59 +0200 Subject: [LTP] [PATCH] lib/tst_timer_test.c: fix unsigned int overflow on RHEL5.11GA In-Reply-To: <597013C1.8030405@cn.fujitsu.com> References: <1500274437-26154-1-git-send-email-yangx.jy@cn.fujitsu.com> <20170719121557.GG1015@rei.lan> <597013C1.8030405@cn.fujitsu.com> Message-ID: <20170720091359.GA27245@rei> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it 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