aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-12-11 18:27:02 +0000
committerPeter Maydell <peter.maydell@linaro.org>2014-12-11 18:27:02 +0000
commit99c9c3cb24e566258a0a141178934f9cb5198842 (patch)
tree4310b60b8ea21fd48304a92244062f8adbcefb92 /util
parentb141290478f847ecaa25561f3b31fbf1ddde95e6 (diff)
parent64baadc2726ae929660dd0c61a42e8d9f3ba1828 (diff)
downloadqemu-99c9c3cb24e566258a0a141178934f9cb5198842.zip
qemu-99c9c3cb24e566258a0a141178934f9cb5198842.tar.gz
qemu-99c9c3cb24e566258a0a141178934f9cb5198842.tar.bz2
Merge remote-tracking branch 'remotes/mjt/tags/pull-trivial-patches-2014-12-11' into staging
trivial patches for 2014-12-11 # gpg: Signature made Thu 11 Dec 2014 18:13:58 GMT using RSA key ID A4C3D7DB # gpg: Good signature from "Michael Tokarev <mjt@tls.msk.ru>" # gpg: aka "Michael Tokarev <mjt@corpit.ru>" # gpg: aka "Michael Tokarev <mjt@debian.org>" * remotes/mjt/tags/pull-trivial-patches-2014-12-11: Sort include/qemu/typedefs.h hpet: increase spelling precision pflash_cfi02.c: associate "cfi.pflash02" to "Storage devices" category vt82c686: fix coverity warning about out-of-bounds write virtio: remove useless declaration of virtio_net_init() qapi-schema: fix typo about change-vnc-password fw_cfg: remove superfluous blank line get_maintainer.pl: Remove the --git-chief-penguins option configure: Replace which(1) with "has" util: Use g_new() & friends where that makes obvious sense util: Fuse g_malloc(); memset() into g_new0() util: Drop superfluous conditionals around g_free() Drop superfluous conditionals around g_strdup() Drop superfluous conditionals around qemu_opts_del() usb: delete redundant brackets in usb_host_handle_control() virtio-bus: avoid breaking build when open DEBUG switch acpi-build: Make DPRINTF working for acpi-build acpi-build: adjust indention 8 -> 4 spaces target-s390x: fix possible out of bounds read qmp: fix typo in input-send-event examples Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r--util/hbitmap.c4
-rw-r--r--util/iov.c4
-rw-r--r--util/uri.c94
3 files changed, 44 insertions, 58 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c
index b3060e6..ab13971 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -373,7 +373,7 @@ void hbitmap_free(HBitmap *hb)
HBitmap *hbitmap_alloc(uint64_t size, int granularity)
{
- HBitmap *hb = g_malloc0(sizeof (struct HBitmap));
+ HBitmap *hb = g_new0(struct HBitmap, 1);
unsigned i;
assert(granularity >= 0 && granularity < 64);
@@ -384,7 +384,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
hb->granularity = granularity;
for (i = HBITMAP_LEVELS; i-- > 0; ) {
size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
- hb->levels[i] = g_malloc0(size * sizeof(unsigned long));
+ hb->levels[i] = g_new0(unsigned long, size);
}
/* We necessarily have free bits in level 0 due to the definition
diff --git a/util/iov.c b/util/iov.c
index 24566c8..2fb18e6 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -253,7 +253,7 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
{
- qiov->iov = g_malloc(alloc_hint * sizeof(struct iovec));
+ qiov->iov = g_new(struct iovec, alloc_hint);
qiov->niov = 0;
qiov->nalloc = alloc_hint;
qiov->size = 0;
@@ -277,7 +277,7 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
if (qiov->niov == qiov->nalloc) {
qiov->nalloc = 2 * qiov->nalloc + 1;
- qiov->iov = g_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
+ qiov->iov = g_renew(struct iovec, qiov->iov, qiov->nalloc);
}
qiov->iov[qiov->niov].iov_base = base;
qiov->iov[qiov->niov].iov_len = len;
diff --git a/util/uri.c b/util/uri.c
index e348c17..918d235 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -225,7 +225,7 @@ rfc3986_parse_scheme(URI *uri, const char **str) {
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) ||
(*cur == '+') || (*cur == '-') || (*cur == '.')) cur++;
if (uri != NULL) {
- if (uri->scheme != NULL) g_free(uri->scheme);
+ g_free(uri->scheme);
uri->scheme = g_strndup(*str, cur - *str);
}
*str = cur;
@@ -262,8 +262,7 @@ rfc3986_parse_fragment(URI *uri, const char **str)
((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))
NEXT(cur);
if (uri != NULL) {
- if (uri->fragment != NULL)
- g_free(uri->fragment);
+ g_free(uri->fragment);
if (uri->cleanup & 2)
uri->fragment = g_strndup(*str, cur - *str);
else
@@ -298,8 +297,7 @@ rfc3986_parse_query(URI *uri, const char **str)
((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))
NEXT(cur);
if (uri != NULL) {
- if (uri->query != NULL)
- g_free (uri->query);
+ g_free(uri->query);
uri->query = g_strndup (*str, cur - *str);
}
*str = cur;
@@ -360,7 +358,7 @@ rfc3986_parse_user_info(URI *uri, const char **str)
NEXT(cur);
if (*cur == '@') {
if (uri != NULL) {
- if (uri->user != NULL) g_free(uri->user);
+ g_free(uri->user);
if (uri->cleanup & 2)
uri->user = g_strndup(*str, cur - *str);
else
@@ -473,9 +471,9 @@ not_ipv4:
NEXT(cur);
found:
if (uri != NULL) {
- if (uri->authority != NULL) g_free(uri->authority);
+ g_free(uri->authority);
uri->authority = NULL;
- if (uri->server != NULL) g_free(uri->server);
+ g_free(uri->server);
if (cur != host) {
if (uri->cleanup & 2)
uri->server = g_strndup(host, cur - host);
@@ -585,7 +583,7 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
if (ret != 0) return(ret);
}
if (uri != NULL) {
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
if (*str != cur) {
if (uri->cleanup & 2)
uri->path = g_strndup(*str, cur - *str);
@@ -631,7 +629,7 @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
}
}
if (uri != NULL) {
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
if (cur != *str) {
if (uri->cleanup & 2)
uri->path = g_strndup(*str, cur - *str);
@@ -673,7 +671,7 @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
if (ret != 0) return(ret);
}
if (uri != NULL) {
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
if (cur != *str) {
if (uri->cleanup & 2)
uri->path = g_strndup(*str, cur - *str);
@@ -715,7 +713,7 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
if (ret != 0) return(ret);
}
if (uri != NULL) {
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
if (cur != *str) {
if (uri->cleanup & 2)
uri->path = g_strndup(*str, cur - *str);
@@ -769,7 +767,7 @@ rfc3986_parse_hier_part(URI *uri, const char **str)
} else {
/* path-empty is effectively empty */
if (uri != NULL) {
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
uri->path = NULL;
}
}
@@ -812,7 +810,7 @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
} else {
/* path-empty is effectively empty */
if (uri != NULL) {
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
uri->path = NULL;
}
}
@@ -1006,8 +1004,7 @@ URI *
uri_new(void) {
URI *ret;
- ret = (URI *) g_malloc(sizeof(URI));
- memset(ret, 0, sizeof(URI));
+ ret = g_new0(URI, 1);
return(ret);
}
@@ -1285,21 +1282,21 @@ static void
uri_clean(URI *uri) {
if (uri == NULL) return;
- if (uri->scheme != NULL) g_free(uri->scheme);
+ g_free(uri->scheme);
uri->scheme = NULL;
- if (uri->server != NULL) g_free(uri->server);
+ g_free(uri->server);
uri->server = NULL;
- if (uri->user != NULL) g_free(uri->user);
+ g_free(uri->user);
uri->user = NULL;
- if (uri->path != NULL) g_free(uri->path);
+ g_free(uri->path);
uri->path = NULL;
- if (uri->fragment != NULL) g_free(uri->fragment);
+ g_free(uri->fragment);
uri->fragment = NULL;
- if (uri->opaque != NULL) g_free(uri->opaque);
+ g_free(uri->opaque);
uri->opaque = NULL;
- if (uri->authority != NULL) g_free(uri->authority);
+ g_free(uri->authority);
uri->authority = NULL;
- if (uri->query != NULL) g_free(uri->query);
+ g_free(uri->query);
uri->query = NULL;
}
@@ -1711,10 +1708,8 @@ uri_resolve(const char *uri, const char *base) {
/*
* the base fragment must be ignored
*/
- if (bas->fragment != NULL) {
- g_free(bas->fragment);
- bas->fragment = NULL;
- }
+ g_free(bas->fragment);
+ bas->fragment = NULL;
val = uri_to_string(bas);
goto done;
}
@@ -1736,24 +1731,21 @@ uri_resolve(const char *uri, const char *base) {
goto done;
if ((ref->scheme == NULL) && (ref->path == NULL) &&
((ref->authority == NULL) && (ref->server == NULL))) {
- if (bas->scheme != NULL)
- res->scheme = g_strdup(bas->scheme);
+ res->scheme = g_strdup(bas->scheme);
if (bas->authority != NULL)
res->authority = g_strdup(bas->authority);
else if (bas->server != NULL) {
- res->server = g_strdup(bas->server);
- if (bas->user != NULL)
- res->user = g_strdup(bas->user);
- res->port = bas->port;
+ res->server = g_strdup(bas->server);
+ res->user = g_strdup(bas->user);
+ res->port = bas->port;
}
- if (bas->path != NULL)
- res->path = g_strdup(bas->path);
- if (ref->query != NULL)
+ res->path = g_strdup(bas->path);
+ if (ref->query != NULL) {
res->query = g_strdup (ref->query);
- else if (bas->query != NULL)
- res->query = g_strdup(bas->query);
- if (ref->fragment != NULL)
- res->fragment = g_strdup(ref->fragment);
+ } else {
+ res->query = g_strdup(bas->query);
+ }
+ res->fragment = g_strdup(ref->fragment);
goto step_7;
}
@@ -1767,13 +1759,10 @@ uri_resolve(const char *uri, const char *base) {
val = uri_to_string(ref);
goto done;
}
- if (bas->scheme != NULL)
- res->scheme = g_strdup(bas->scheme);
+ res->scheme = g_strdup(bas->scheme);
- if (ref->query != NULL)
- res->query = g_strdup(ref->query);
- if (ref->fragment != NULL)
- res->fragment = g_strdup(ref->fragment);
+ res->query = g_strdup(ref->query);
+ res->fragment = g_strdup(ref->fragment);
/*
* 4) If the authority component is defined, then the reference is a
@@ -1787,20 +1776,17 @@ uri_resolve(const char *uri, const char *base) {
res->authority = g_strdup(ref->authority);
else {
res->server = g_strdup(ref->server);
- if (ref->user != NULL)
- res->user = g_strdup(ref->user);
+ res->user = g_strdup(ref->user);
res->port = ref->port;
}
- if (ref->path != NULL)
- res->path = g_strdup(ref->path);
+ res->path = g_strdup(ref->path);
goto step_7;
}
if (bas->authority != NULL)
res->authority = g_strdup(bas->authority);
else if (bas->server != NULL) {
- res->server = g_strdup(bas->server);
- if (bas->user != NULL)
- res->user = g_strdup(bas->user);
+ res->server = g_strdup(bas->server);
+ res->user = g_strdup(bas->user);
res->port = bas->port;
}