Message ID | 4931941.GXAFRqVoOG@devpool47.emlix.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | improve qconfig C++ code | expand |
On Wed, Oct 23, 2024 at 3:29 PM Rolf Eike Beer <eb@emlix.com> wrote: > > 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> > --- I do not need this patch because I can refactor this function even deeper. I have locally kept several clean-up patches, but I have not got around to submitting them. I will send some of them later.
On Thu, Oct 24, 2024 at 1:37 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Wed, Oct 23, 2024 at 3:29 PM Rolf Eike Beer <eb@emlix.com> wrote: > > > > 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> > > --- > > I do not need this patch because I can refactor this function even deeper. > > I have locally kept several clean-up patches, but I have not got around to > submitting them. > > I will send some of them later. https://lore.kernel.org/linux-kbuild/20241023181823.138524-12-masahiroy@kernel.org/T/#u
On Mittwoch, 23. Oktober 2024 21:07:41 Mitteleuropäische Sommerzeit Masahiro Yamada wrote: > On Thu, Oct 24, 2024 at 1:37 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Wed, Oct 23, 2024 at 3:29 PM Rolf Eike Beer <eb@emlix.com> wrote: > > > 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> > > > --- > > > > I do not need this patch because I can refactor this function even deeper. > > > > I have locally kept several clean-up patches, but I have not got around to > > submitting them. > > > > I will send some of them later. > > https://lore.kernel.org/linux-kbuild/20241023181823.138524-12-masahiroy@kern > el.org/T/#u Even better, thanks!
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)
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(-)