|
From: Konstantin S. <kon...@gm...> - 2009-02-23 07:20:08
|
On Mon, Feb 23, 2009 at 9:30 AM, Nicholas Nethercote
<n.n...@gm...> wrote:
> Hi,
>
> This code is from coregrind/m_libcbase.c:
>
> void* VG_(memmove)(void *dest, const void *src, SizeT sz)
> {
> SizeT i;
> if (sz == 0)
> return dest;
> if (dest < src) {
> for (i = 0; i < sz; i++) {
> ((UChar*)dest)[i] = ((UChar*)src)[i];
> }
> }
> else if (dest > src) {
> for (i = sz - 1; i >= 0; i--) {
> ((UChar*)dest)[i] = ((UChar*)src)[i];
> }
> }
> return dest;
> }
>
> It has a 50% chance of crashing or looping infinitely. Why? The
> condition of the for-loop in the else-branch never fails, because i is
> unsigned. Fortunately this function is not actually used anywhere.
Anywhere in the trunk -- yes.
But I've hit this crash in Dec when I started using STL in valgrind
(STL uses memmove).
The patch I use is this:
else if (dest > src) {
UChar *d = (UChar*)dest + sz - 1;
UChar *s = (UChar*)src + sz - 1;
for (; d >= (UChar*)dest; d--, s--) {
*d = *s;
}
}
>
> The warning -Wtype-limits finds this problem, and 185 other ones like
> it (ie. comparisons that are always true or false) in the core and
> tools, and some more in the tests. I've looked at a few of these,
> some of them are just redundant assertions that an unsigned value is
> greater than zero, but even those are worrying.
>
> I'd like to turn this warning on. Possibly via -Wextra, which brings
> some other warnings into the mix, but if so then -Wno-sign-compare and
> -Wno-unused-parameter would also be needed to avoid lots of IMHO
> unimportant warnings. Thoughts?
--kcc
>
> Nick
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Valgrind-developers mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-developers
>
|