All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ján Tomko" <jtomko@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH] util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic
Date: Tue, 9 Sep 2025 16:20:55 +0200	[thread overview]
Message-ID: <aMA3x0V_AHrlwP2o@fedora> (raw)
In-Reply-To: <aL7tdmmT0ZEVZ1qb@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1737 bytes --]

On a Monday in 2025, Daniel P. Berrangé wrote:
>On Fri, Sep 05, 2025 at 05:20:06PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> QEMU_HEXDUMP_LINE_WIDTH calculation doesn't correspond to
>> qemu_hexdump_line(). This leads to last line of the dump (when
>> length is not multiply of 16) has badly aligned ASCII part.
>>
>> Let's calculate length the same way.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
>> ---
>>  util/hexdump.c | 38 ++++++++++++++++++++++++--------------
>>  1 file changed, 24 insertions(+), 14 deletions(-)
>
>Would you mind also adding a test to tests/unit/test-cutils.c
>to show the correctness, as this is a nice standalone func
>we ought to be unit testing.
>
>>
>> diff --git a/util/hexdump.c b/util/hexdump.c
>> index f29ffceb74..7cfc547261 100644
>> --- a/util/hexdump.c
>> +++ b/util/hexdump.c
>> @@ -30,14 +43,8 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len,
>>
>>      if (str == NULL) {
>>          /* Estimate the length of the output to avoid reallocs. */
>> -        size_t est = len * 2;
>> -        if (unit_len) {
>> -            est += len / unit_len;
>> -        }
>> -        if (block_len) {
>> -            est += len / block_len;
>> -        }
>> -        str = g_string_sized_new(est + 1);
>> +        str = g_string_sized_new(hexdump_line_length(len, unit_len, block_len)
>> +                                 + 1);

Fun fact: with new enough glib, this will allocate a buffer of 128 bytes (nearest
power of 64+1) anyway:
https://gitlab.gnome.org/GNOME/glib/-/commit/7fc7c57b6fd470bbee267471a61c714f3a0d281c

Jano

>>      }
>>
>>      for (u = 0, b = 0; len; u++, b++, len--, buf++) {

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

      parent reply	other threads:[~2025-09-09 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 14:20 [PATCH] util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic Vladimir Sementsov-Ogievskiy
2025-09-08 14:51 ` Daniel P. Berrangé
2025-09-08 16:03   ` Vladimir Sementsov-Ogievskiy
2025-09-09 14:20   ` Ján Tomko [this message]

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=aMA3x0V_AHrlwP2o@fedora \
    --to=jtomko@redhat.com \
    --cc=berrange@redhat.com \
    --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.