[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [Qemu-devel] [PATCH for-2.1] test-string-output-visit
From: |
Eric Blake |
Subject: |
Re: [Qemu-trivial] [Qemu-devel] [PATCH for-2.1] test-string-output-visitor: Fix unterminated string |
Date: |
Wed, 09 Jul 2014 19:41:17 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
On 07/09/2014 08:14 AM, Kevin Wolf wrote:
> Don't forget to add a terminating '\0' or the test case will be randomly
> failing. The broken code was added in commit b4900c0e.
Sorry, but I prefer this solution better:
https://lists.gnu.org/archive/html/qemu-devel/2014-07/msg01595.html
>
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
> tests/test-string-output-visitor.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/test-string-output-visitor.c
> b/tests/test-string-output-visitor.c
> index e89e43c..f2c427f 100644
> --- a/tests/test-string-output-visitor.c
> +++ b/tests/test-string-output-visitor.c
> @@ -201,11 +201,11 @@ static void test_visitor_out_enum(TestOutputVisitorData
> *data,
> visit_type_EnumOne(data->ov, &i, "unused", &err);
> g_assert(!err);
>
> - len = strlen(EnumOne_lookup[i]) + 2;
> + len = strlen(EnumOne_lookup[i]) + 3;
> str_human = g_malloc0(len);
> str_human[0] = '"';
> strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
> - str_human[len - 1] = '"';
> + str_human[len - 2] = '"';
Manually doing this when g_strdup_printf can do it as a one-liner is
just lunacy.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature