From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
qemu-devel@nongnu.org, philmd@linaro.org
Subject: Re: [PATCH v3] tests/unit: add unit test for qemu_hexdump()
Date: Thu, 13 Nov 2025 11:35:22 +0000 [thread overview]
Message-ID: <aRXCes0Y2xMPYfS2@redhat.com> (raw)
In-Reply-To: <CAFEAcA8433bHWqbb0cC2myY=7NKqPb1M3r+y3_mXH=QQuCoYJQ@mail.gmail.com>
On Thu, Nov 13, 2025 at 10:46:42AM +0000, Peter Maydell wrote:
> On Thu, 13 Nov 2025 at 10:33, Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Thu, Nov 13, 2025 at 01:20:15PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> > > On 13.11.25 12:10, Daniel P. Berrangé wrote:
> > > > On Thu, Nov 13, 2025 at 09:49:35AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> > > > > Test, that fix in previous commit make sense.
> > > > >
> > > > > To not break compilation when we build without
> > > > > 'block', move hexdump.c out of "if have_block"
> > > > > in meson.build.
> > > > >
> > > > > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > > > > ---
> > > > >
> > > > > v3: change meson.build to compile hexdump.c always
> > > > >
> > > > > tests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++
> > > > > util/meson.build | 2 +-
> > > > > 2 files changed, 44 insertions(+), 1 deletion(-)
> > > >
> > > > > +static void test_qemu_hexdump_alignment(void)
> > > > > +{
> > > > > + /*
> > > > > + * Test that ASCII part is properly aligned for incomplete lines.
> > > > > + * This test catches the bug that was fixed in previous commit
> > > > > + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic".
> > > > > + *
> > > > > + * We use data that is not aligned to 16 bytes, so last line
> > > > > + * is incomplete.
> > > > > + */
> > > > > + const uint8_t data[] = {
> > > > > + /* First line: 16 bytes */
> > > > > + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */
> > > > > + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */
> > > > > + /* Second line: 5 bytes (incomplete) */
> > > > > + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */
> > > > > + };
> > > > > + char *output = NULL;
> > > >
> > > > Could be g_autofree, and avoid the later 'free()' call.
> > >
> > > I'm not sure that it's correct to replace free() by g_free()..
> > >
> > > Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
> >
> > Note where it says:
> >
> > "Since GLib 2.46, g_malloc() is hardcoded to always use the system
> > malloc implementation."
> >
> > I added that guarantee to glib docs specifically so apps no longer
> > have to match free with g_free. You should still not mix up the
> > C free vs C++ delete, or free vs g_slice_free, but that's not an
> > issue for QEMU.
>
> I think for this specific case (the buffer allocated by
> open_memstream()) it's probably better to use explicit
> free(), because the criterion for "when is it OK to free
> this?" is not "when the pointer goes out of scope" but
> "when we have called fclose() on the stream". Auto-freeing
> the buffer by returning without closing the file would
> be a bug.
Oh good point, lets just leave this as-is.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2025-11-13 11:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 6:49 [PATCH v3] tests/unit: add unit test for qemu_hexdump() Vladimir Sementsov-Ogievskiy
2025-11-13 9:10 ` Daniel P. Berrangé
2025-11-13 10:20 ` Vladimir Sementsov-Ogievskiy
2025-11-13 10:33 ` Daniel P. Berrangé
2025-11-13 10:44 ` Vladimir Sementsov-Ogievskiy
2025-11-13 10:46 ` Peter Maydell
2025-11-13 11:35 ` Daniel P. Berrangé [this message]
2025-11-13 13:03 ` Vladimir Sementsov-Ogievskiy
2025-11-13 13:56 ` Eric Blake
2025-11-13 17:39 ` Vladimir Sementsov-Ogievskiy
2025-11-13 21:01 ` Philippe Mathieu-Daudé
2026-01-19 15:42 ` Vladimir Sementsov-Ogievskiy
2026-01-19 16:31 ` Philippe Mathieu-Daudé
2026-01-19 17:26 ` Vladimir Sementsov-Ogievskiy
2026-01-19 18:38 ` Philippe Mathieu-Daudé
2026-01-19 19:15 ` Vladimir Sementsov-Ogievskiy
2026-01-19 19:18 ` Vladimir Sementsov-Ogievskiy
2026-01-19 19:29 ` Philippe Mathieu-Daudé
2026-01-20 16:38 ` Philippe Mathieu-Daudé
2026-01-20 17:15 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aRXCes0Y2xMPYfS2@redhat.com \
--to=berrange@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.