[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 44/60] acpi: Simplify printing to dynamic string
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL v2 44/60] acpi: Simplify printing to dynamic string |
Date: |
Mon, 1 Jun 2015 14:25:01 +0200 |
From: Markus Armbruster <address@hidden>
build_append_namestringv() and aml_string() first calculate the
resulting string's length with vsnprintf(NULL, ...), then allocate,
then print for real. Simply use g_strdup_vprintf() or g_vasprintf()
instead.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: John Snow <address@hidden>
Reviewed-by: Igor Mammedov <address@hidden>
---
hw/acpi/aml-build.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 323b7bc..4cc0c61 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -19,6 +19,7 @@
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include <glib/gprintf.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
@@ -59,7 +60,6 @@ static void build_append_array(GArray *array, GArray *val)
static void
build_append_nameseg(GArray *array, const char *seg)
{
- /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
int len;
len = strlen(seg);
@@ -73,22 +73,12 @@ build_append_nameseg(GArray *array, const char *seg)
static void GCC_FMT_ATTR(2, 0)
build_append_namestringv(GArray *array, const char *format, va_list ap)
{
- /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
char *s;
- int len;
- va_list va_len;
char **segs;
char **segs_iter;
int seg_count = 0;
- va_copy(va_len, ap);
- len = vsnprintf(NULL, 0, format, va_len);
- va_end(va_len);
- len += 1;
- s = g_new(typeof(*s), len);
-
- len = vsnprintf(s, len, format, ap);
-
+ s = g_strdup_vprintf(format, ap);
segs = g_strsplit(s, ".", 0);
g_free(s);
@@ -753,22 +743,15 @@ Aml *aml_create_dword_field(Aml *srcbuf, Aml *index,
const char *name)
Aml *aml_string(const char *name_format, ...)
{
Aml *var = aml_opcode(0x0D /* StringPrefix */);
- va_list ap, va_len;
+ va_list ap;
char *s;
int len;
va_start(ap, name_format);
- va_copy(va_len, ap);
- len = vsnprintf(NULL, 0, name_format, va_len);
- va_end(va_len);
- len += 1;
- s = g_new0(typeof(*s), len);
-
- len = vsnprintf(s, len, name_format, ap);
+ len = g_vasprintf(&s, name_format, ap);
va_end(ap);
- g_array_append_vals(var->buf, s, len);
- build_append_byte(var->buf, 0x0); /* NullChar */
+ g_array_append_vals(var->buf, s, len + 1);
g_free(s);
return var;
--
MST
- [Qemu-devel] [PULL v2 37/60] virtio-s390: introduce virtio_s390_device_plugged(), (continued)
- [Qemu-devel] [PULL v2 37/60] virtio-s390: introduce virtio_s390_device_plugged(), Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 38/60] virtio: rename VIRTIO_PCI_QUEUE_MAX to VIRTIO_QUEUE_MAX, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 39/60] virtio: increase the queue limit to 1024, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 40/60] i386/pc: pc_basic_device_init(): delegate FDC creation request, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 41/60] i386/pc: '-drive if=floppy' should imply a board-default FDC, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 43/60] i386: drop FDC in pc-q35-2.4+ if neither it nor floppy drives are wanted, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 42/60] i386/pc_q35: don't insist on board FDC if there's no default floppy, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 44/60] acpi: Simplify printing to dynamic string,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL v2 45/60] Add stream ID to MSI write, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 46/60] Extend TPM TIS interface to support TPM 2, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 47/60] tpm: Probe for connected TPM 1.2 or TPM 2, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 48/60] TPM2 ACPI table support, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 49/60] acpi: add aml_add() term, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 50/60] acpi: add aml_lless() term, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 51/60] acpi: add aml_index() term, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 53/60] acpi: add aml_shiftright() term, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 52/60] acpi: add aml_shiftleft() term, Michael S. Tsirkin, 2015/06/01
- [Qemu-devel] [PULL v2 54/60] acpi: add aml_increment() term, Michael S. Tsirkin, 2015/06/01