Hi Ben,

vsnprintf returns the size that was truncated. So we need at least
ds->allocated + needed bytes to print the full string.
        needed = vsnprintf(&ds->string[ds->length], available, format,
args);

So ds_reserve should make sure ds contains at least ds->allocated + needed
bytes.
        ds_reserve(ds, ds->allocated + needed);

For example, if ds starts with:
length = 4, allocated = 8
Assume the to-be-printed string length = 10, then we got needed = 2
In current code, ds_reserve(4 + 2 = 6) is called, if go into ds_reserve(),
since (6 < 8), ds_reserve actually does nothing.

Thanks,
Yifeng

On Tue, Jul 24, 2018 at 2:47 PM, Ben Pfaff <b...@ovn.org> wrote:

> On Tue, Jul 24, 2018 at 08:37:08AM -0700, Yifeng Sun wrote:
> > 'needed' should be size of needed memory space beyond allocated.
> >
> > Signed-off-by: Yifeng Sun <pkusunyif...@gmail.com>
> > Reported-by: Yun Zhou <y...@nvidia.com>
> > Reported-by: Girish Moodalbail <gmoodalb...@gmail.com>
>
> I don't see a bug here.  Can you explain why you think that there is a
> bug?
>
> (I note that this code dates back to before 2008.)
>
> Thanks,
>
> Ben.
>
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to