qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Emilio G. Cota" <cota@braap.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Changlong Xie <xiecl.fnst@cn.fujitsu.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] qht: do not segfault when gathering stats from an uninitialized qht
Date: Sat, 23 Jul 2016 19:09:01 -0400	[thread overview]
Message-ID: <20160723230901.GA10429@flamenco> (raw)
In-Reply-To: <f20f643c-90f4-bd1c-8055-9204e7502e25@redhat.com>

On Sat, Jul 23, 2016 at 12:54:51 +0200, Paolo Bonzini wrote:
> On 23/07/2016 12:01, Peter Maydell wrote:
> > On 22 July 2016 at 17:36, Emilio G. Cota <cota@braap.org> wrote:
> > This looks like we're passing NULL pointers to
> > printf %s specifiers. This is undefined behaviour at least
> > for POSIX printf, and I can't see anything in the glib
> > printf-alike function documentation that gives an extra
> > guarantee for this, so it's probably a bad idea.
> > 
> > Printing 'nan' also looks a bit odd, though it's not UB.
> 
> Let's move everything to a new function, so that it's easy to add a
> check at the top:

I'm OK with this.

Regardless, it's probably a good idea to also add the appended
to qdist, since as Peter points out passing NULL to printf is
undefined.

[ Note that we need to return a dup'ed
string, since callers are supposed to call g_free() on it when
they're done.]

If there's interest, I'll send a proper patch on Monday.

Thanks,

		E.

diff --git a/tests/test-qdist.c b/tests/test-qdist.c
index 0298986..0a03635 100644
--- a/tests/test-qdist.c
+++ b/tests/test-qdist.c
@@ -360,10 +360,10 @@ static void test_none(void)
     g_assert(isnan(qdist_xmax(&dist)));
 
     pr = qdist_pr_plain(&dist, 0);
-    g_assert(pr == NULL);
+    g_assert_cmpstr(pr, ==, "(empty)");
 
     pr = qdist_pr_plain(&dist, 2);
-    g_assert(pr == NULL);
+    g_assert_cmpstr(pr, ==, "(empty)");
 
     qdist_destroy(&dist);
 }
diff --git a/util/qdist.c b/util/qdist.c
index 56f5738..a43f464 100644
--- a/util/qdist.c
+++ b/util/qdist.c
@@ -234,7 +234,7 @@ char *qdist_pr_plain(const struct qdist *dist, size_t n)
     char *ret;
 
     if (dist->n == 0) {
-        return NULL;
+        return g_strdup("(empty)");
     }
     qdist_bin__internal(&binned, dist, n);
     ret = qdist_pr_internal(&binned);

  reply	other threads:[~2016-07-23 23:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-10 14:26 [Qemu-devel] [PULL 00/15] tb hash improvements Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 01/15] compiler.h: add QEMU_ALIGNED() to enforce struct alignment Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 02/15] seqlock: remove optional mutex Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 03/15] seqlock: rename write_lock/unlock to write_begin/end Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 04/15] include/processor.h: define cpu_relax() Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 05/15] qemu-thread: add simple test-and-set spinlock Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 06/15] exec: add tb_hash_func5, derived from xxhash Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 07/15] tb hash: hash phys_pc, pc, and flags with xxhash Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 08/15] qdist: add module to represent frequency distributions of data Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 09/15] qdist: add test program Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 10/15] qht: QEMU's fast, resizable and scalable Hash Table Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 11/15] qht: add test program Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 12/15] qht: add qht-bench, a performance benchmark Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 13/15] qht: add test-qht-par to invoke qht-bench from 'check' target Richard Henderson
2016-06-10 14:26 ` [Qemu-devel] [PULL 14/15] tb hash: track translated blocks with qht Richard Henderson
2016-08-10 13:36   ` Igor Mammedov
2016-08-10 19:25     ` [Qemu-devel] [PATCH] qht: support resetting an uninitialized qht Emilio G. Cota
2016-08-11  8:43       ` Igor Mammedov
2016-06-10 14:26 ` [Qemu-devel] [PULL 15/15] translate-all: add tb hash bucket info to 'info jit' dump Richard Henderson
2016-07-22  9:04   ` Changlong Xie
2016-07-22 16:36     ` [Qemu-devel] [PATCH] qht: do not segfault when gathering stats from an uninitialized qht Emilio G. Cota
2016-07-23  7:45       ` Paolo Bonzini
2016-07-23 10:01       ` Peter Maydell
2016-07-23 10:54         ` Paolo Bonzini
2016-07-23 23:09           ` Emilio G. Cota [this message]
2016-06-10 15:33 ` [Qemu-devel] [PULL 00/15] tb hash improvements Peter Maydell
2016-06-10 15:57   ` Peter Maydell
2016-06-10 16:34   ` Emilio G. Cota
2016-06-10 16:41     ` Peter Maydell
2016-06-10 19:24       ` Emilio G. Cota
2016-06-11 23:09       ` Richard Henderson

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=20160723230901.GA10429@flamenco \
    --to=cota@braap.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=xiecl.fnst@cn.fujitsu.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).