Oooooook....
The problem: Valgrind throws a warning in the mysql-6.0-rpl tree that the
calculation for string length (str_length) in this code is violating
allocated memory. Specifically, that there is uninitialized data. On some
platforms (it seems), there is exactly 1 extra byte allocated for string
length thus Valgrind 'thinks' we are using memory in the array without
assigning it a value. But we aren't because it's perfectly fine to allocate
more memory than you need (but wasteful in large quantities naturally). The
solution I formed originally was to eliminate the extra position. But now it
seems at least one platform needs that extra byte. That is probably how it
got there in the first place. ;)
This alternative solution recalculates the string length based on what gets
stored in the string (at ptr()). Thus, this solution will work on all
platforms. Is it a hack? Well, I'll defend it as a workaround but if someone
has a better explanation or solution I'm all ears.
So, as reviewer, would you concur that this is a valid solution given the
need to solve the Valgrind problem and the inconsistent behaviour across
platforms WRT string length?
If so, I will create a new patch with a more detailed set of comments.
Chuck
> -----Original Message-----
> From: Jorgen.Loland@stripped [mailto:Jorgen.Loland@stripped]
> Sent: Sunday, September 28, 2008 14:30 PM
> To: Chuck Bell
> Subject: Re: bzr commit into mysql-6.0-rpl branch
> (cbell:2696) Bug#39598
>
> Chuck Bell wrote:
> > Jorgen,
> >
> > Would you mind trying this alternative? If it still truncates I may
> > need you to help me diagnose the problem.
> >
> > === modified file 'sql/backup/stream.cc'
> > --- sql/backup/stream.cc 2008-08-08 17:21:31 +0000
> > +++ sql/backup/stream.cc 2008-09-26 16:03:37 +0000
> > @@ -343,7 +343,8 @@ int Stream::prepare_path(::String *backu
> > m_path.length(0);
> > m_path.append(orig_loc.str);
> > }
> > - m_path.length(path_len);
> > + // Reset the str_length.
> > + m_path.length(strlen(m_path.ptr()));
> > return 0;
> > }
> >
> > Thanks,
> >
> > Chuck
>
> Yep, that did it :)
>
> But I don't see why that should make a difference. Do you
> have a theory?
> Anyway, good work!
>
> Jørgen
>