[PATCH 1/7] kconfig: qconf: use QByteArray API instead of manually constructing a string

Rolf Eike Beer
2024-10-23T06:38:41Z

Using a naked char[] here isn't necessary as QByteArray has a nice API for all
of this. Calling constData() will also always return a 0-terminated string so no
further handling is required. And then the whole manual memory handling can go
away as QByteArray will care for this when it goes out of scope.

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
---
scripts/kconfig/qconf.cc | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index e260cab1c2af..742ca6ed289b 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -1165,25 +1165,17 @@ void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char
void ConfigInfoView::clicked(const QUrl &url)
{
QByteArray str = url.toEncoded();
- const std::size_t count = str.size();
- char *data = new char[count + 2]; // '$' + '\0'
struct symbol **result;
struct menu *m = NULL;

- if (count < 1) {
- delete[] data;
+ if (str.isEmpty())
return;
- }
-
- memcpy(data, str.constData(), count);
- data[count] = '\0';

/* Seek for exact match */
- data[0] = '^';
- strcat(data, "$");
- result = sym_re_search(data);
+ str[0] = '^';
+ str.append('$');
+ result = sym_re_search(str.constData());
if (!result) {
- delete[] data;
return;
}

@@ -1206,7 +1198,6 @@ void ConfigInfoView::clicked(const QUrl &url)
}

free(result);
- delete[] data;
}

void ConfigInfoView::contextMenuEvent(QContextMenuEvent *event)
--
2.47.0