[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 4/4] qjson: surprise, allocating 6 QObjects per
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 4/4] qjson: surprise, allocating 6 QObjects per token is expensive |
Date: |
Fri, 20 Nov 2015 21:19:02 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 20/11/2015 19:48, Eric Blake wrote:
>> > + token = g_malloc(sizeof(JSONToken) + input->len + 1);
>> > + token->type = type;
>> > + memcpy(token->str, input->str, input->len + 1);
>> > + token->str[input->len] = 0;
> Looks like you are writing the last byte twice. Either the +1 in the
> memcpy() always copies a NUL byte and we don't need the second
> assignment, or you should drop the +1.
>
> Otherwise, looks like a sane replacement that saves a lot of memory.
You're right. The memcpy is wrong and reads out of bounds.
Paolo
> Reviewed-by: Eric Blake <address@hidden>
>
> Are we hoping to get this in 2.5 because it fixes the memory hog bug, or
> are we considering that it is not a regression from 2.4 and therefore
> something that should wait for 2.6?
- [Qemu-devel] [PATCH 2/4] qjson: do not save/restore contexts, (continued)