Message ID | 20131121091506.GA22462@redhat.com |
---|---|
State | New |
Headers | show |
On 21 November 2013 09:15, Michael S. Tsirkin <mst@redhat.com> wrote: > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c > index 486e705..97e0fba 100644 > --- a/hw/i386/acpi-build.c > +++ b/hw/i386/acpi-build.c > @@ -287,14 +287,17 @@ static inline void build_append_array(GArray *array, GArray *val) > > static void build_append_nameseg(GArray *array, const char *format, ...) > { > - GString *s = g_string_new(""); > + /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */ > + char s[] = "XXXX"; > + int len; > va_list args; > > va_start(args, format); > g_string_vprintf(s, format, args); > + len = vsnprintf(s, sizeof s, format, args); > va_end(args); ...this patch doesn't seem to have removed the g_string_vprintf call? thanks -- PMM
On Thu, Nov 21, 2013 at 10:09:58AM +0000, Peter Maydell wrote: > On 21 November 2013 09:15, Michael S. Tsirkin <mst@redhat.com> wrote: > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c > > index 486e705..97e0fba 100644 > > --- a/hw/i386/acpi-build.c > > +++ b/hw/i386/acpi-build.c > > @@ -287,14 +287,17 @@ static inline void build_append_array(GArray *array, GArray *val) > > > > static void build_append_nameseg(GArray *array, const char *format, ...) > > { > > - GString *s = g_string_new(""); > > + /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */ > > + char s[] = "XXXX"; > > + int len; > > va_list args; > > > > va_start(args, format); > > g_string_vprintf(s, format, args); > > + len = vsnprintf(s, sizeof s, format, args); > > va_end(args); > > ...this patch doesn't seem to have removed the g_string_vprintf > call? > > thanks > -- PMM yes and I found more issues. Pls don't test yet I'll post v2.
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 486e705..97e0fba 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -287,14 +287,17 @@ static inline void build_append_array(GArray *array, GArray *val) static void build_append_nameseg(GArray *array, const char *format, ...) { - GString *s = g_string_new(""); + /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */ + char s[] = "XXXX"; + int len; va_list args; va_start(args, format); g_string_vprintf(s, format, args); + len = vsnprintf(s, sizeof s, format, args); va_end(args); - assert(s->len == 4); + assert(len == 4); g_array_append_vals(array, s->str, s->len); g_string_free(s, true); } @@ -424,7 +427,10 @@ static inline void *acpi_data_push(GArray *table_data, unsigned size) static unsigned acpi_data_len(GArray *table) { - return table->len * g_array_get_element_size(table); +#if GLIB_CHECK_VERSION(2, 14, 0) + assert(g_array_get_element_size(table) == 1); +#endif + return table->len; } static void acpi_align_size(GArray *blob, unsigned align)