Re: [PATCH] zero-terminate result of target_read_alloc

Daniel Jacobowitz
2006-07-18T12:34:44Z

On Tue, Jul 18, 2006 at 01:25:22PM +0200, Mark Kettenis wrote:
> >
> > This patch makes result of target_read_alloc zero-terminated.
> > The point is that often the object is not allowed to contain embedded
> > zeros,
> > and working with zero-terminated strings is much easier.
> >
> > OK?
>
> This is wrong. Either the terminating nul is part of the object you're
> reading or it is not. GDB shouldn't at its own.

I figured the same but actually reading a couple of objects and
managing them convinced me that Volodya's right. Note that he's not
adding one to the length returned - if you want binary data, you'll get
binary data. It just allows you to easily treat the result as a string
if you plan to treat it as a string anyway.

As you can probably guess from context, we have these bunches of XML
files that we read from the target and then do text processing on.
On the branch where I developed the XML bits for the first time, I
didn't think to make this change - so the very first thing I had to do
with the result of target_read_alloc was to allocate something one byte
bigger with a NUL on the end of it!

--
Daniel Jacobowitz
CodeSourcery