diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-05-01 14:38:24 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-05-01 17:11:10 +0200 |
commit | 59fb18bf279446ba8d26faf7bfb03e375e0aac62 (patch) | |
tree | b278b11974656f7f6b67278b3b6da9e9baf20e1f /desktop | |
parent | 1ac07d2c9d45cc5db3f689d287ad9be939ef1124 (diff) |
next is never passed a null pointer, use a reference
Change-Id: I6d57e6a7f746a05017c6f93ef434a234716259c2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166965
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/desktop_app/test_desktop_app.cxx | 5 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.cxx | 21 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.hxx | 2 | ||||
-rw-r--r-- | desktop/source/app/officeipcthread.cxx | 11 |
4 files changed, 18 insertions, 21 deletions
diff --git a/desktop/qa/desktop_app/test_desktop_app.cxx b/desktop/qa/desktop_app/test_desktop_app.cxx index 0e86368e6378..2c9c7ba7121b 100644 --- a/desktop/qa/desktop_app/test_desktop_app.cxx +++ b/desktop/qa/desktop_app/test_desktop_app.cxx @@ -48,10 +48,9 @@ public: explicit TestSupplier(const std::initializer_list<OUString>& args) : m_args(args) {} virtual std::optional< OUString > getCwdUrl() override { return std::optional< OUString >(); } - virtual bool next(OUString * argument) override { - CPPUNIT_ASSERT(argument != nullptr); + virtual bool next(OUString& argument) override { if (m_index < m_args.size()) { - *argument = m_args[m_index++]; + argument = m_args[m_index++]; return true; } else { diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx index f96814e8e7ff..ba5a3da5a6c3 100644 --- a/desktop/source/app/cmdlineargs.cxx +++ b/desktop/source/app/cmdlineargs.cxx @@ -83,10 +83,9 @@ public: virtual std::optional< OUString > getCwdUrl() override { return m_cwdUrl; } - virtual bool next(OUString * argument) override { - OSL_ASSERT(argument != nullptr); + virtual bool next(OUString& argument) override { if (m_index < m_count) { - rtl_getAppCommandArg(m_index++, &argument->pData); + rtl_getAppCommandArg(m_index++, &argument.pData); return true; } else { return false; @@ -285,7 +284,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) for (;;) { OUString aArg; - if ( !supplier.next( &aArg ) ) + if ( !supplier.next(aArg) ) { break; } @@ -410,7 +409,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) // We specifically need to consume the following 2 arguments // for --protector - if ((!supplier.next(&aArg) || !supplier.next(&aArg)) && m_unknown.isEmpty()) + if ((!supplier.next(aArg) || !supplier.next(aArg)) && m_unknown.isEmpty()) m_unknown = "--protector must be followed by two arguments"; } else if ( oArg == "version" ) @@ -523,7 +522,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) // Print to special printer eCurrentEvent = CommandLineEvent::PrintTo; // first argument after "-pt" must be the printer name - if (supplier.next(&aArg)) + if (supplier.next(aArg)) m_printername = aArg; else if (m_unknown.isEmpty()) m_unknown = "--pt must be followed by printername"; @@ -550,13 +549,13 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) // --display and its argument are handled "out of line" // in Unix-only desktop/unx/source/splashx.c and vcl/unx/*, // and just ignored here - (void)supplier.next(&aArg); + (void)supplier.next(aArg); } else if ( oArg == "convert-to" ) { eCurrentEvent = CommandLineEvent::Conversion; // first argument must be the params - if (supplier.next(&aArg)) + if (supplier.next(aArg)) { m_conversionparams = aArg; // It doesn't make sense to use convert-to without headless. @@ -574,7 +573,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) if (eCurrentEvent == CommandLineEvent::BatchPrint) { // first argument is the printer name - if (supplier.next(&aArg)) + if (supplier.next(aArg)) m_printername = aArg; else if (m_unknown.isEmpty()) m_unknown = "--printer-name must be followed by printername"; @@ -589,7 +588,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) if (eCurrentEvent == CommandLineEvent::Conversion || eCurrentEvent == CommandLineEvent::BatchPrint) { - if (supplier.next(&aArg)) + if (supplier.next(aArg)) m_conversionout = aArg; else if (m_unknown.isEmpty()) m_unknown = "--outdir must be followed by output directory path"; @@ -602,7 +601,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) else if ( eCurrentEvent == CommandLineEvent::Conversion && oArg == "convert-images-to" ) { - if (supplier.next(&aArg)) + if (supplier.next(aArg)) m_convertimages = aArg; else if (m_unknown.isEmpty()) m_unknown = "--convert-images-to must be followed by an image type"; diff --git a/desktop/source/app/cmdlineargs.hxx b/desktop/source/app/cmdlineargs.hxx index a9eca1d980f1..59cd741a8c3f 100644 --- a/desktop/source/app/cmdlineargs.hxx +++ b/desktop/source/app/cmdlineargs.hxx @@ -45,7 +45,7 @@ class CommandLineArgs virtual ~Supplier(); virtual std::optional< OUString > getCwdUrl() = 0; - virtual bool next(OUString * argument) = 0; + virtual bool next(OUString& argument) = 0; }; CommandLineArgs(); diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx index 9d342bf35a84..1378c91bf6c6 100644 --- a/desktop/source/app/officeipcthread.cxx +++ b/desktop/source/app/officeipcthread.cxx @@ -115,7 +115,7 @@ public: case '1': { OUString url; - if (!next(&url, false)) { + if (!next(url, false)) { throw CommandLineArgs::Supplier::Exception(); } m_cwdUrl = url; @@ -124,7 +124,7 @@ public: case '2': { OUString path; - if (!next(&path, false)) { + if (!next(path, false)) { throw CommandLineArgs::Supplier::Exception(); } OUString url; @@ -142,11 +142,10 @@ public: virtual std::optional< OUString > getCwdUrl() override { return m_cwdUrl; } - virtual bool next(OUString * argument) override { return next(argument, true); } + virtual bool next(OUString& argument) override { return next(argument, true); } private: - bool next(OUString * argument, bool prefix) { - OSL_ASSERT(argument != nullptr); + bool next(OUString& argument, bool prefix) { if (m_index < m_input.getLength()) { if (prefix) { if (m_input[m_index] != ',') { @@ -180,7 +179,7 @@ private: } OString b2(b.makeStringAndClear()); if (!rtl_convertStringToUString( - &argument->pData, b2.getStr(), b2.getLength(), + &argument.pData, b2.getStr(), b2.getLength(), RTL_TEXTENCODING_UTF8, (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | |