mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-11-05 20:35:44 +00:00
qdict: fix unbounded stack warning for qdict_array_entries
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> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
1d817db3a0
commit
de4905f4bc
1 changed files with 8 additions and 11 deletions
|
@ -705,19 +705,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;
|
||||
|
||||
snprintf_ret = snprintf(indexstr, slen, "%s%u", subqdict, i);
|
||||
assert(snprintf_ret < slen);
|
||||
|
||||
subqobj = qdict_get(src, indexstr);
|
||||
|
||||
snprintf_ret = snprintf(prefix, slen, "%s%u.", subqdict, i);
|
||||
assert(snprintf_ret < slen);
|
||||
char *prefix = g_strdup_printf("%s%u.", subqdict, i);
|
||||
|
||||
subqdict_entries = qdict_count_prefixed_entries(src, prefix);
|
||||
|
||||
/* Remove ending "." */
|
||||
prefix[strlen(prefix) - 1] = 0;
|
||||
subqobj = qdict_get(src, prefix);
|
||||
|
||||
g_free(prefix);
|
||||
|
||||
if (subqdict_entries < 0) {
|
||||
return subqdict_entries;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue