diff options
author | Emilio G. Cota <cota@braap.org> | 2016-07-25 11:03:45 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-08-03 18:44:56 +0200 |
commit | 11b7b07f8a15879134a54e73fade98d5e11e04f8 (patch) | |
tree | f3ca6774ea7b23a2fb01ed45874d4f375fb10da4 /util/qdist.c | |
parent | 071d4054770205ddb8a58a9e2735069d8fe52af1 (diff) |
qdist: return "(empty)" instead of NULL when printing an empty dist
Printf'ing a NULL string is undefined behaviour. Avoid it.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <1469459025-23606-4-git-send-email-cota@braap.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/qdist.c')
-rw-r--r-- | util/qdist.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/util/qdist.c b/util/qdist.c index e95722b8a1..5f75e24c29 100644 --- a/util/qdist.c +++ b/util/qdist.c @@ -14,6 +14,8 @@ #define NAN (0.0 / 0.0) #endif +#define QDIST_EMPTY_STR "(empty)" + void qdist_init(struct qdist *dist) { dist->entries = g_new(struct qdist_entry, 1); @@ -233,7 +235,7 @@ char *qdist_pr_plain(const struct qdist *dist, size_t n) char *ret; if (dist->n == 0) { - return NULL; + return g_strdup(QDIST_EMPTY_STR); } qdist_bin__internal(&binned, dist, n); ret = qdist_pr_internal(&binned); @@ -308,7 +310,7 @@ char *qdist_pr(const struct qdist *dist, size_t n_bins, uint32_t opt) GString *s; if (dist->n == 0) { - return NULL; + return g_strdup(QDIST_EMPTY_STR); } s = g_string_new(""); |