* [Qemu-devel] [PATCH v2] qdict: fix unbounded stack warning for qdict_array_entries
@ 2016-03-22 2:37 Peter Xu
2016-03-22 15:39 ` Markus Armbruster
0 siblings, 1 reply; 3+ messages in thread
From: Peter Xu @ 2016-03-22 2:37 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, pbonzini, armbru, peterx
Here we use one g_strdup_printf() to replace the two stack allocated
array, considering it's more convenient, safe, and as long as it's
called rarely only when quorum device opens. This will remove the
unbound stack warning when compiling with "-Wstack-usage=1000000".
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
qobject/qdict.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 9833bd0..fe6ffa1 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -704,19 +704,16 @@ int qdict_array_entries(QDict *src, const char *subqdict)
for (i = 0; i < INT_MAX; i++) {
QObject *subqobj;
int subqdict_entries;
- size_t slen = 32 + subqdict_len;
- char indexstr[slen], prefix[slen];
- size_t snprintf_ret;
+ char *prefix = g_strdup_printf("%s%u.", subqdict, i);
- snprintf_ret = snprintf(indexstr, slen, "%s%u", subqdict, i);
- assert(snprintf_ret < slen);
+ subqdict_entries = qdict_count_prefixed_entries(src, prefix);
- subqobj = qdict_get(src, indexstr);
+ /* Remove ending "." */
+ prefix[strlen(prefix) - 1] = 0;
+ subqobj = qdict_get(src, prefix);
- snprintf_ret = snprintf(prefix, slen, "%s%u.", subqdict, i);
- assert(snprintf_ret < slen);
+ g_free(prefix);
- subqdict_entries = qdict_count_prefixed_entries(src, prefix);
if (subqdict_entries < 0) {
return subqdict_entries;
}
--
2.4.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qdict: fix unbounded stack warning for qdict_array_entries
2016-03-22 2:37 [Qemu-devel] [PATCH v2] qdict: fix unbounded stack warning for qdict_array_entries Peter Xu
@ 2016-03-22 15:39 ` Markus Armbruster
2016-05-06 18:39 ` Michael Tokarev
0 siblings, 1 reply; 3+ messages in thread
From: Markus Armbruster @ 2016-03-22 15:39 UTC (permalink / raw)
To: Peter Xu; +Cc: kwolf, pbonzini, qemu-trivial, qemu-devel, Luiz Capitulino
Peter Xu <peterx@redhat.com> writes:
> Here we use one g_strdup_printf() to replace the two stack allocated
> array, considering it's more convenient, safe, and as long as it's
> called rarely only when quorum device opens. This will remove the
> unbound stack warning when compiling with "-Wstack-usage=1000000".
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
I lack the time to take this through my tree before my Easter vacation.
Nominating for qemu-trivial, assuming Luiz doesn't mind.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qdict: fix unbounded stack warning for qdict_array_entries
2016-03-22 15:39 ` Markus Armbruster
@ 2016-05-06 18:39 ` Michael Tokarev
0 siblings, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2016-05-06 18:39 UTC (permalink / raw)
To: Markus Armbruster, Peter Xu
Cc: kwolf, pbonzini, qemu-trivial, qemu-devel, Luiz Capitulino
22.03.2016 18:39, Markus Armbruster wrote:
> Peter Xu <peterx@redhat.com> writes:
>
>> Here we use one g_strdup_printf() to replace the two stack allocated
>> array, considering it's more convenient, safe, and as long as it's
>> called rarely only when quorum device opens. This will remove the
>> unbound stack warning when compiling with "-Wstack-usage=1000000".
>>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> Signed-off-by: Peter Xu <peterx@redhat.com>
>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>
> I lack the time to take this through my tree before my Easter vacation.
> Nominating for qemu-trivial, assuming Luiz doesn't mind.
(Finally) applied to -trivial, thanks!
/mjt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-06 18:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-22 2:37 [Qemu-devel] [PATCH v2] qdict: fix unbounded stack warning for qdict_array_entries Peter Xu
2016-03-22 15:39 ` Markus Armbruster
2016-05-06 18:39 ` Michael Tokarev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).