diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 6a95aa6c92..bc1784c30e 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -737,11 +737,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, * l1_table_offset when it is the current s->l1_table_offset! Be careful * when changing this! */ if (l1_table_offset != s->l1_table_offset) { - if (l1_size2 != 0) { - l1_table = g_malloc0(align_offset(l1_size2, 512)); - } else { - l1_table = NULL; - } + l1_table = g_malloc0(align_offset(l1_size2, 512)); l1_allocated = 1; if (bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2) != l1_size2) diff --git a/block/vdi.c b/block/vdi.c index 257a592ea9..87c691b504 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -443,9 +443,7 @@ static int vdi_open(BlockDriverState *bs, int flags) bmap_size = header.blocks_in_image * sizeof(uint32_t); bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE; - if (bmap_size > 0) { - s->bmap = g_malloc(bmap_size * SECTOR_SIZE); - } + s->bmap = g_malloc(bmap_size * SECTOR_SIZE); ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size); if (ret < 0) { goto fail_free_bmap; diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index 6b9afd32d5..36f66163b2 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -1039,7 +1039,7 @@ int main(int argc, char **argv) } switch (c) { case 'p': - rpath = strdup(optarg); + rpath = g_strdup(optarg); break; case 'n': is_daemon = false; @@ -1048,7 +1048,7 @@ int main(int argc, char **argv) sock = atoi(optarg); break; case 's': - sock_name = strdup(optarg); + sock_name = g_strdup(optarg); break; case 'u': own_u = atoi(optarg); diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 6f427dfc5d..74155fb61e 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -85,11 +85,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) } s->ctx.export_flags = fse->export_flags; - if (fse->path) { - s->ctx.fs_root = g_strdup(fse->path); - } else { - s->ctx.fs_root = NULL; - } + s->ctx.fs_root = g_strdup(fse->path); s->ctx.exops.get_st_gen = NULL; len = strlen(conf->tag); if (len > MAX_TAG_LEN - 1) { @@ -98,7 +94,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) exit(1); } - s->tag = strdup(conf->tag); + s->tag = g_strdup(conf->tag); s->ctx.uid = -1; s->ops = fse->ops; diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index 113602144c..f1b1c83a22 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -46,7 +46,7 @@ static const char *local_mapped_attr_path(FsContext *ctx, const char *path, char *buffer) { char *dir_name; - char *tmp_path = strdup(path); + char *tmp_path = g_strdup(path); char *base_name = basename(tmp_path); /* NULL terminate the directory */ @@ -55,7 +55,7 @@ static const char *local_mapped_attr_path(FsContext *ctx, snprintf(buffer, PATH_MAX, "%s/%s/%s/%s", ctx->fs_root, dir_name, VIRTFS_META_DIR, base_name); - free(tmp_path); + g_free(tmp_path); return buffer; } @@ -130,7 +130,7 @@ static int local_create_mapped_attr_dir(FsContext *ctx, const char *path) { int err; char attr_dir[PATH_MAX]; - char *tmp_path = strdup(path); + char *tmp_path = g_strdup(path); snprintf(attr_dir, PATH_MAX, "%s/%s/%s", ctx->fs_root, dirname(tmp_path), VIRTFS_META_DIR); @@ -139,7 +139,7 @@ static int local_create_mapped_attr_dir(FsContext *ctx, const char *path) if (err < 0 && errno == EEXIST) { err = 0; } - free(tmp_path); + g_free(tmp_path); return err; } diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 0aaf0d2de0..b795839620 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -3101,11 +3101,7 @@ static void v9fs_xattrcreate(void *opaque) xattr_fidp->fs.xattr.flags = flags; v9fs_string_init(&xattr_fidp->fs.xattr.name); v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name); - if (size) { - xattr_fidp->fs.xattr.value = g_malloc(size); - } else { - xattr_fidp->fs.xattr.value = NULL; - } + xattr_fidp->fs.xattr.value = g_malloc(size); err = offset; put_fid(pdu, file_fidp); out_nofid: diff --git a/hw/block-common.c b/hw/block-common.c index 0f1b64ec95..d21ec3ada1 100644 --- a/hw/block-common.c +++ b/hw/block-common.c @@ -18,9 +18,7 @@ void blkconf_serial(BlockConf *conf, char **serial) if (!*serial) { /* try to fall back to value set with legacy -drive serial=... */ dinfo = drive_get_by_blockdev(conf->bs); - if (dinfo->serial) { - *serial = g_strdup(dinfo->serial); - } + *serial = g_strdup(dinfo->serial); } } diff --git a/hw/cadence_gem.c b/hw/cadence_gem.c index 0d834422df..b77423d449 100644 --- a/hw/cadence_gem.c +++ b/hw/cadence_gem.c @@ -687,14 +687,15 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) packet_desc_addr = s->rx_desc_addr; while (1) { - DB_PRINT("read descriptor 0x%x\n", packet_desc_addr); + DB_PRINT("read descriptor 0x%x\n", (unsigned)packet_desc_addr); /* read current descriptor */ cpu_physical_memory_read(packet_desc_addr, (uint8_t *)&desc[0], sizeof(desc)); /* Descriptor owned by software ? */ if (rx_desc_get_ownership(desc) == 1) { - DB_PRINT("descriptor 0x%x owned by sw.\n", packet_desc_addr); + DB_PRINT("descriptor 0x%x owned by sw.\n", + (unsigned)packet_desc_addr); s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_NOBUF; /* Handle interrupt consequences */ gem_update_int_status(s); @@ -709,7 +710,7 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) */ if (rx_desc_get_buffer(desc) == 0) { DB_PRINT("Invalid RX buffer (NULL) for descriptor 0x%x\n", - packet_desc_addr); + (unsigned)packet_desc_addr); break; } @@ -749,7 +750,7 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) s->rx_desc_addr += 8; } - DB_PRINT("set SOF, OWN on descriptor 0x%08x\n", packet_desc_addr); + DB_PRINT("set SOF, OWN on descriptor 0x%08x\n", (unsigned)packet_desc_addr); /* Count it */ gem_receive_updatestats(s, buf, size); @@ -861,7 +862,8 @@ static void gem_transmit(GemState *s) */ if ((tx_desc_get_buffer(desc) == 0) || (tx_desc_get_length(desc) == 0)) { - DB_PRINT("Invalid TX descriptor @ 0x%x\n", packet_desc_addr); + DB_PRINT("Invalid TX descriptor @ 0x%x\n", + (unsigned)packet_desc_addr); break; } @@ -1031,10 +1033,11 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size) offset >>= 2; retval = s->regs[offset]; - DB_PRINT("offset: 0x%04x read: 0x%08x\n", offset*4, retval); + DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval); switch (offset) { case GEM_ISR: + DB_PRINT("lowering irq on ISR read\n"); qemu_set_irq(s->irq, 0); break; case GEM_PHYMNTNC: @@ -1073,7 +1076,7 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val, GemState *s = (GemState *)opaque; uint32_t readonly; - DB_PRINT("offset: 0x%04x write: 0x%08x ", offset, (unsigned)val); + DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val); offset >>= 2; /* Squash bits which are read only in write value */ diff --git a/hw/cadence_ttc.c b/hw/cadence_ttc.c index 2a8fadd810..67028a3f75 100644 --- a/hw/cadence_ttc.c +++ b/hw/cadence_ttc.c @@ -302,7 +302,7 @@ static uint64_t cadence_ttc_read(void *opaque, hwaddr offset, { uint32_t ret = cadence_ttc_read_imp(opaque, offset); - DB_PRINT("addr: %08x data: %08x\n", offset, ret); + DB_PRINT("addr: %08x data: %08x\n", (unsigned)offset, (unsigned)ret); return ret; } @@ -311,7 +311,7 @@ static void cadence_ttc_write(void *opaque, hwaddr offset, { CadenceTimerState *s = cadence_timer_from_addr(opaque, offset); - DB_PRINT("addr: %08x data %08x\n", offset, (unsigned)value); + DB_PRINT("addr: %08x data %08x\n", (unsigned)offset, (unsigned)value); cadence_timer_sync(s); diff --git a/hw/vhost.c b/hw/vhost.c index cee8aad4a1..0dd2a9aa40 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -269,11 +269,8 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size) vhost_log_chunk_t *log; uint64_t log_base; int r, i; - if (size) { - log = g_malloc0(size * sizeof *log); - } else { - log = NULL; - } + + log = g_malloc0(size * sizeof *log); log_base = (uint64_t)(unsigned long)log; r = ioctl(dev->control, VHOST_SET_LOG_BASE, &log_base); assert(r >= 0); diff --git a/hw/xilinx_axidma.c b/hw/xilinx_axidma.c index d0ee566a28..cc51584dfc 100644 --- a/hw/xilinx_axidma.c +++ b/hw/xilinx_axidma.c @@ -444,7 +444,7 @@ static void axidma_write(void *opaque, hwaddr addr, break; default: D(qemu_log("%s: ch=%d addr=" TARGET_FMT_plx " v=%x\n", - __func__, sid, addr * 4, value)); + __func__, sid, addr * 4, (unsigned)value)); s->regs[addr] = value; break; } diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h index 016fd87726..b032f529aa 100644 --- a/include/ui/qemu-pixman.h +++ b/include/ui/qemu-pixman.h @@ -15,7 +15,7 @@ #pragma GCC diagnostic error "-Wredundant-decls" #endif -#include "console.h" +#include "qemu/typedefs.h" /* * pixman image formats are defined to be native endian, diff --git a/include/ui/spice-display.h b/include/ui/spice-display.h index 8b192e9613..46f9530fe3 100644 --- a/include/ui/spice-display.h +++ b/include/ui/spice-display.h @@ -21,6 +21,7 @@ #include "qemu/thread.h" #include "ui/qemu-pixman.h" +#include "ui/console.h" #include "sysemu/sysemu.h" #define NUM_MEMSLOTS 8 diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c index 5f565e0b4a..df79476db8 100644 --- a/libcacard/vcard_emul_nss.c +++ b/libcacard/vcard_emul_nss.c @@ -454,7 +454,7 @@ vreader_emul_new(PK11SlotInfo *slot, VCardEmulType type, const char *params) new_reader_emul->slot = PK11_ReferenceSlot(slot); new_reader_emul->default_type = type; - new_reader_emul->type_params = strdup(params); + new_reader_emul->type_params = g_strdup(params); new_reader_emul->present = PR_FALSE; new_reader_emul->series = 0; new_reader_emul->saved_vcard = NULL; @@ -997,7 +997,7 @@ vcard_emul_init(const VCardEmulOptions *options) /* We should control this with options. For now we mirror out any * removable hardware slot */ default_card_type = options->hw_card_type; - default_type_params = strdup(options->hw_type_params); + default_type_params = g_strdup(options->hw_type_params); SECMOD_GetReadLock(module_lock); for (mlp = module_list; mlp; mlp = mlp->next) { diff --git a/libcacard/vreader.c b/libcacard/vreader.c index 313349b656..f3efc270a2 100644 --- a/libcacard/vreader.c +++ b/libcacard/vreader.c @@ -49,7 +49,7 @@ vreader_new(const char *name, VReaderEmul *private, reader = (VReader *)g_malloc(sizeof(VReader)); qemu_mutex_init(&reader->lock); reader->reference_count = 1; - reader->name = name ? strdup(name) : NULL; + reader->name = g_strdup(name); reader->card = NULL; reader->id = (vreader_id_t)-1; reader->reader_private = private; diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c index 2fce52bed5..9b744f249c 100644 --- a/libcacard/vscclient.c +++ b/libcacard/vscclient.c @@ -503,8 +503,8 @@ main( command_line_options = vcard_emul_options(emul_args); } - qemu_host = strdup(argv[argc - 2]); - qemu_port = strdup(argv[argc - 1]); + qemu_host = g_strdup(argv[argc - 2]); + qemu_port = g_strdup(argv[argc - 1]); sock = connect_to_qemu(qemu_host, qemu_port); if (sock == -1) { fprintf(stderr, "error opening socket, exiting.\n"); diff --git a/net/net.c b/net/net.c index cdd9b04989..2f0ab3a121 100644 --- a/net/net.c +++ b/net/net.c @@ -566,9 +566,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name, assert(peer); nd->netdev = peer; } - if (name) { - nd->name = g_strdup(name); - } + nd->name = g_strdup(name); if (nic->has_model) { nd->model = g_strdup(nic->model); } diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index 70cdbca470..28bbbe849e 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -92,7 +92,7 @@ char **qmp_get_command_list(void) list_head = list = g_malloc0(count * sizeof(char *)); QTAILQ_FOREACH(cmd, &qmp_commands, node) { - *list = strdup(cmd->name); + *list = g_strdup(cmd->name); list++; } diff --git a/qemu-log.c b/qemu-log.c index b655b305ea..30c9ab01bd 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -21,10 +21,12 @@ #include "qemu/log.h" #ifdef WIN32 -static const char *logfilename = "qemu.log"; +#define DEFAULT_LOGFILENAME "qemu.log" #else -static const char *logfilename = "/tmp/qemu.log"; +#define DEFAULT_LOGFILENAME "/tmp/qemu.log" #endif + +static char *logfilename; FILE *qemu_logfile; int qemu_loglevel; static int log_append = 0; @@ -54,11 +56,13 @@ void qemu_log_mask(int mask, const char *fmt, ...) /* enable or disable low levels log */ void qemu_set_log(int log_flags, bool use_own_buffers) { + const char *fname = logfilename ?: DEFAULT_LOGFILENAME; + qemu_loglevel = log_flags; if (qemu_loglevel && !qemu_logfile) { - qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); + qemu_logfile = fopen(fname, log_append ? "a" : "w"); if (!qemu_logfile) { - perror(logfilename); + perror(fname); _exit(1); } /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ @@ -84,7 +88,8 @@ void qemu_set_log(int log_flags, bool use_own_buffers) void cpu_set_log_filename(const char *filename) { - logfilename = strdup(filename); + g_free(logfilename); + logfilename = g_strdup(filename); if (qemu_logfile) { fclose(qemu_logfile); qemu_logfile = NULL; diff --git a/qga/commands.c b/qga/commands.c index 7ffb35e4af..528b082fa8 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -61,7 +61,7 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) while (*cmd_list) { cmd_info = g_malloc0(sizeof(GuestAgentCommandInfo)); - cmd_info->name = strdup(*cmd_list); + cmd_info->name = g_strdup(*cmd_list); cmd_info->enabled = qmp_command_is_enabled(cmd_info->name); cmd_info_list = g_malloc0(sizeof(GuestAgentCommandInfoList)); diff --git a/qmp-commands.hx b/qmp-commands.hx index f58a8411ea..f90efe590c 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1659,7 +1659,7 @@ Each json-object contain the following: - Possible values: "unknown" - "removable": true if the device is removable, false otherwise (json-bool) - "locked": true if the device is locked, false otherwise (json-bool) -- "tray-open": only present if removable, true if the device has a tray, +- "tray_open": only present if removable, true if the device has a tray, and it is open (json-bool) - "inserted": only present if the device is inserted, it is a json-object containing the following: diff --git a/readline.c b/readline.c index a0c9638e4d..d6e04d4796 100644 --- a/readline.c +++ b/readline.c @@ -247,14 +247,14 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline) } if (idx == READLINE_MAX_CMDS) { /* Need to get one free slot */ - free(rs->history[0]); + g_free(rs->history[0]); memmove(rs->history, &rs->history[1], (READLINE_MAX_CMDS - 1) * sizeof(char *)); rs->history[READLINE_MAX_CMDS - 1] = NULL; idx = READLINE_MAX_CMDS - 1; } if (new_entry == NULL) - new_entry = strdup(cmdline); + new_entry = g_strdup(cmdline); rs->history[idx] = new_entry; rs->hist_entry = -1; } diff --git a/slirp/slirp.c b/slirp/slirp.c index e93b578832..0e6e232789 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -225,12 +225,8 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork, pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname), vhostname); } - if (tftp_path) { - slirp->tftp_prefix = g_strdup(tftp_path); - } - if (bootfile) { - slirp->bootp_filename = g_strdup(bootfile); - } + slirp->tftp_prefix = g_strdup(tftp_path); + slirp->bootp_filename = g_strdup(bootfile); slirp->vdhcp_startaddr = vdhcp_start; slirp->vnameserver_addr = vnameserver; diff --git a/tests/m48t59-test.c b/tests/m48t59-test.c index d79f55472d..77d69b330d 100644 --- a/tests/m48t59-test.c +++ b/tests/m48t59-test.c @@ -142,7 +142,9 @@ static void cmos_get_date_time(struct tm *date) date->tm_mday = mday; date->tm_mon = mon - 1; date->tm_year = base_year + year - 1900; +#ifndef __sun__ date->tm_gmtoff = 0; +#endif ts = mktime(date); } diff --git a/tests/rtc-test.c b/tests/rtc-test.c index e7123cafbc..203c0fc363 100644 --- a/tests/rtc-test.c +++ b/tests/rtc-test.c @@ -115,7 +115,9 @@ static void cmos_get_date_time(struct tm *date) date->tm_mday = mday; date->tm_mon = mon - 1; date->tm_year = base_year + year - 1900; +#ifndef __sun__ date->tm_gmtoff = 0; +#endif ts = mktime(date); } diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index 609335ab11..6dcbe90546 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -3,7 +3,8 @@ * See the COPYING file in the top-level directory. */ -#include "ui/qemu-pixman.h" +#include "qemu-common.h" +#include "ui/console.h" int qemu_pixman_get_type(int rshift, int gshift, int bshift) { diff --git a/ui/spice-core.c b/ui/spice-core.c index 3f2c5650cd..bcc4199e7a 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -848,8 +848,8 @@ static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_conn) int qemu_spice_set_passwd(const char *passwd, bool fail_if_conn, bool disconnect_if_conn) { - free(auth_passwd); - auth_passwd = strdup(passwd); + g_free(auth_passwd); + auth_passwd = g_strdup(passwd); return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn); } diff --git a/ui/vnc-ws.c b/ui/vnc-ws.c index 9ccdc1971c..3e3020916c 100644 --- a/ui/vnc-ws.c +++ b/ui/vnc-ws.c @@ -120,10 +120,11 @@ static char *vncws_extract_handshake_entry(const char *handshake, static void vncws_send_handshake_response(VncState *vs, const char* key) { char combined_key[WS_CLIENT_KEY_LEN + WS_GUID_LEN + 1]; - char hash[SHA1_DIGEST_LEN]; - size_t hash_size = SHA1_DIGEST_LEN; + unsigned char hash[SHA1_DIGEST_LEN]; + size_t hash_size = sizeof(hash); char *accept = NULL, *response = NULL; gnutls_datum_t in; + int ret; g_strlcpy(combined_key, key, WS_CLIENT_KEY_LEN + 1); g_strlcat(combined_key, WS_GUID, WS_CLIENT_KEY_LEN + WS_GUID_LEN + 1); @@ -131,9 +132,9 @@ static void vncws_send_handshake_response(VncState *vs, const char* key) /* hash and encode it */ in.data = (void *)combined_key; in.size = WS_CLIENT_KEY_LEN + WS_GUID_LEN; - if (gnutls_fingerprint(GNUTLS_DIG_SHA1, &in, hash, &hash_size) - == GNUTLS_E_SUCCESS) { - accept = g_base64_encode((guchar *)hash, SHA1_DIGEST_LEN); + ret = gnutls_fingerprint(GNUTLS_DIG_SHA1, &in, hash, &hash_size); + if (ret == GNUTLS_E_SUCCESS && hash_size <= SHA1_DIGEST_LEN) { + accept = g_base64_encode(hash, hash_size); } if (accept == NULL) { VNC_DEBUG("Hashing Websocket combined key failed\n"); diff --git a/util/qemu-option.c b/util/qemu-option.c index f532b765a0..c12e7245ef 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -643,9 +643,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value, QTAILQ_INSERT_TAIL(&opts->head, opt, next); } opt->desc = desc; - if (value) { - opt->str = g_strdup(value); - } + opt->str = g_strdup(value); qemu_opt_parse(opt, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err); @@ -792,9 +790,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, } } opts = g_malloc0(sizeof(*opts)); - if (id) { - opts->id = g_strdup(id); - } + opts->id = g_strdup(id); opts->list = list; loc_save(&opts->loc); QTAILQ_INIT(&opts->head);