From fa19a9ddbdddeaed44480ce7dade11d526336435 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 11 Sep 2024 16:57:04 +0000 Subject: Acknowledge non-erase usage of remove_if for volatile sources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc produces a length warning starting with: | warning: ignoring return value of ‘_FIter std::remove_if(_FIter, _FIter, _Predicate) [with …]’, declared with attribute ‘nodiscard’ [-Wunused-result] which is usually correct, but in the usage here we don't want to call an erase as we operate on a c-style new[] array here which contains pointers into argv and has an explicit sentinel (nullptr) – FileSize() is based on this sentinel. Casting to void silences the warning as is standard practice and hopefully indicates better that this is intended than ignoring the warning for the casual on-looker. --- apt-pkg/sourcelist.cc | 2 +- apt-private/private-install.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 65412b458..819344281 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -614,7 +614,7 @@ bool pkgSourceList::AddVolatileFile(std::string const &File) /*}}}*/ void pkgSourceList::AddVolatileFiles(CommandLine &CmdL, std::vector * const VolatileCmdL)/*{{{*/ { - std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const * const I) { + (void)std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const * const I) { if (I != nullptr && (I[0] == '/' || (I[0] == '.' && (I[1] == '\0' || (I[1] == '.' && (I[2] == '\0' || I[2] == '/')) || I[1] == '/')))) { if (AddVolatileFile(I, VolatileCmdL)) diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 57b5c0d5e..3f05cf9fb 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -986,7 +986,7 @@ std::vector GetAllPackagesAsPseudo(pkgSourceList *const SL, CommandLi std::vector GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector &), std::string const &pseudoArch)/*{{{*/ { std::vector VolatileCmdL; - std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const *const I) { + (void)std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const *const I) { return AddIfVolatile(SL, VolatileCmdL, Add, I, pseudoArch); }); return VolatileCmdL; -- cgit v1.2.3-70-g09d2 From baf93ab433283bf836848035afa31690b30868a5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 11 Sep 2024 18:30:40 +0000 Subject: Fix expired std::string usage in APT::StringView testcase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The anonymous std::string we were using here to create the view expires after the construction of the view and so the gcc warning | warning: ‘’ may be used uninitialized [-Wmaybe-uninitialized] is correct in that the memory we are pointing to is potentially overridden/reused already, if a bit roundabout in saying so. --- test/libapt/stringview_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/libapt/stringview_test.cc b/test/libapt/stringview_test.cc index 5abb7a8e1..5b82a0da5 100644 --- a/test/libapt/stringview_test.cc +++ b/test/libapt/stringview_test.cc @@ -35,7 +35,8 @@ TEST(StringViewTest,FooString) static_assert( 3 == defString.length(), "def right size"); EXPECT_EQ(0, defString.to_string().compare(0, defString.length(), defString.data(), 3)); - APT::StringView strString{std::string{"foo"}}; + std::string strstr{"foo"}; + APT::StringView strString{strstr}; EXPECT_EQ(3u, strString.length()); EXPECT_EQ(0, strString.to_string().compare(0, strString.length(), strString.data(), 3)); -- cgit v1.2.3-70-g09d2 From 0fb71e375363f2b45b033bb2b324e80214325c61 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 11 Sep 2024 19:52:26 +0000 Subject: Add a virtual destructor to private CacheSet Matcher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This silences the warning: | warning: ‘class Matcher’ has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor] --- apt-private/private-cacheset.h | 1 + 1 file changed, 1 insertion(+) diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index e8dba5a7d..cad8e4a00 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -68,6 +68,7 @@ class Matcher { public: virtual bool operator () (const pkgCache::PkgIterator &/*P*/) { return true;} + virtual ~Matcher() = default; }; // FIXME: add default argument for OpProgress (or overloaded function) -- cgit v1.2.3-70-g09d2 From 7578b7031921231400be78fa8c2893bbd5ea18df Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 19 Nov 2024 21:58:13 +0000 Subject: Avoid unnormalized paths for CMake install destinations CMake 3.31 is very noisy about our manpage (and to a lesser extend documentation in general) building as we used "//" and "/../" there. `cmake --help-policy CMP0177` documents the warning, so we could just decide on a value and deal with it, but given our usage is not really needed and rather trivial to change lets not pick a value and instead use a normalized path so we don't use different code paths in CMake depending on which CMake version we happen to be build with. --- CMake/Documentation.cmake | 4 +++- doc/CMakeLists.txt | 7 ++++--- doc/examples/CMakeLists.txt | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMake/Documentation.cmake b/CMake/Documentation.cmake index f3eb4c5e1..d7f136020 100644 --- a/CMake/Documentation.cmake +++ b/CMake/Documentation.cmake @@ -154,14 +154,16 @@ function(xsltproc_one) if (DOC_MANPAGE) if (language) set(manpage_output "${CMAKE_CURRENT_BINARY_DIR}/${language}/${document}.${section}") + set(manpage_l10npath "/${language}") else() + set(manpage_l10npath "") set(manpage_output "${CMAKE_CURRENT_BINARY_DIR}/${document}.${section}") endif() set(manpage_stylesheet "${CMAKE_CURRENT_BINARY_DIR}/manpage-style.xsl") set(manpage_params) install(FILES ${manpage_output} - DESTINATION ${CMAKE_INSTALL_MANDIR}/${language}/man${section} + DESTINATION ${CMAKE_INSTALL_MANDIR}${manpage_l10npath}/man${section} OPTIONAL) endif() if (DOC_HTML) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 72a1fed88..493c36c08 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -22,13 +22,14 @@ set(ENTITIES apt-verbatim.ent ../vendor/${CURRENT_VENDOR}/apt-vendor.ent ) +set(USR_SHARE_DOC "${CMAKE_INSTALL_DATAROOTDIR}/doc") if(WITH_DOC OR WITH_DOC_GUIDES) add_docbook(apt-doc HTML TEXT ALL DOCUMENTS guide.dbk offline.dbk - INSTALL ${CMAKE_INSTALL_DOCDIR}/../apt-doc + INSTALL ${USR_SHARE_DOC}/apt-doc LINGUAS ${LINGUAS} TRANSLATED_ENTITIES ${TRANSLATED_ENTITIES} DEPENDS ${ENTITIES} @@ -40,7 +41,7 @@ add_docbook(libapt-pkg-doc HTML TEXT ALL dpkg-tech.dbk files.dbk method.dbk - INSTALL ${CMAKE_INSTALL_DOCDIR}/../libapt-pkg-doc + INSTALL ${USR_SHARE_DOC}/libapt-pkg-doc LINGUAS ${LINGUAS} TRANSLATED_ENTITIES ${TRANSLATED_ENTITIES} DEPENDS ${ENTITIES} @@ -65,7 +66,7 @@ add_custom_target(apt-doxygen ALL ) install(DIRECTORY ${PROJECT_BINARY_DIR}/doc/doxygen/html - DESTINATION ${CMAKE_INSTALL_DOCDIR}/../libapt-pkg-doc + DESTINATION ${USR_SHARE_DOC}/libapt-pkg-doc PATTERN "*.map" EXCLUDE PATTERN "*.md5" EXCLUDE ) diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt index 8d9ea068f..be638d081 100644 --- a/doc/examples/CMakeLists.txt +++ b/doc/examples/CMakeLists.txt @@ -1,4 +1,4 @@ install(FILES apt.conf configure-index preferences DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) install(FILES apt-ftparchive.conf ftp-archive.conf - DESTINATION ${CMAKE_INSTALL_DOCDIR}/../apt-utils/examples) + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/apt-utils/examples) -- cgit v1.2.3-70-g09d2 From 8c760266c8c736bff62055c008ab74d78f3ed82a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 19 Nov 2024 22:42:44 +0000 Subject: Tag hidden acquire classes as final for devirtualization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc reports `warning: Declaring type ‘class X’ final would enable devirtualization of Y calls [-Wsuggest-final-types]`. Not that this would massively improve performance, but it shouldn't hurt telling the compiler what is obvious for a human. --- apt-pkg/acquire-item.cc | 4 ++-- apt-pkg/acquire-item.h | 12 ++++++------ methods/connect.cc | 4 ++-- methods/copy.cc | 2 +- methods/file.cc | 2 +- methods/http.cc | 2 +- methods/http.h | 4 ++-- methods/rred.cc | 2 +- methods/store.cc | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 12292eb28..73e9940ee 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -717,7 +717,7 @@ bool pkgAcqIndexDiffs::AcquireByHash() const } /*}}}*/ -class APT_HIDDEN NoActionItem : public pkgAcquire::Item /*{{{*/ +class APT_HIDDEN NoActionItem final : public pkgAcquire::Item /*{{{*/ /* The sole purpose of this class is having an item which does nothing to reach its done state to prevent cleanup deleting the mentioned file. Handy in cases in which we know we have the file already, like IMS-Hits. */ @@ -741,7 +741,7 @@ class APT_HIDDEN NoActionItem : public pkgAcquire::Item /*{{{*/ } }; /*}}}*/ -class APT_HIDDEN CleanupItem : public pkgAcqTransactionItem /*{{{*/ +class APT_HIDDEN CleanupItem final : public pkgAcqTransactionItem /*{{{*/ /* This class ensures that a file which was configured but isn't downloaded for various reasons isn't kept in an old version in the lists directory. In a way its the reverse of NoActionItem as it helps with removing files diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 22da9815d..cfea61cf6 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -530,7 +530,7 @@ class APT_HIDDEN pkgAcqMetaIndex : public pkgAcqMetaBase * * \sa pkgAcqMetaIndex */ -class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem +class APT_HIDDEN pkgAcqMetaSig final : public pkgAcqTransactionItem { void * const d; @@ -560,7 +560,7 @@ class APT_HIDDEN pkgAcqMetaSig : public pkgAcqTransactionItem }; /*}}}*/ /** \brief An item responsible for downloading clearsigned metaindexes {{{*/ -class APT_HIDDEN pkgAcqMetaClearSig : public pkgAcqMetaIndex +class APT_HIDDEN pkgAcqMetaClearSig final : public pkgAcqMetaIndex { void * const d; IndexTarget const DetachedDataTarget; @@ -707,7 +707,7 @@ struct APT_HIDDEN DiffInfo { /*{{{*/ * * \sa pkgAcqIndexDiffs, pkgAcqIndex */ -class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqIndex +class APT_HIDDEN pkgAcqDiffIndex final : public pkgAcqIndex { void * const d; std::vector * diffs; @@ -773,7 +773,7 @@ class APT_HIDDEN pkgAcqDiffIndex : public pkgAcqIndex * * \sa pkgAcqDiffIndex, pkgAcqIndex */ -class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex +class APT_HIDDEN pkgAcqIndexMergeDiffs final : public pkgAcqBaseIndex { protected: @@ -848,7 +848,7 @@ class APT_HIDDEN pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex * * \sa pkgAcqDiffIndex, pkgAcqIndex */ -class APT_HIDDEN pkgAcqIndexDiffs : public pkgAcqBaseIndex +class APT_HIDDEN pkgAcqIndexDiffs final : public pkgAcqBaseIndex { private: @@ -1194,7 +1194,7 @@ class APT_PUBLIC pkgAcqFile : public pkgAcquire::Item virtual ~pkgAcqFile(); }; /*}}}*/ -class APT_HIDDEN pkgAcqAuxFile : public pkgAcqFile /*{{{*/ +class APT_HIDDEN pkgAcqAuxFile final : public pkgAcqFile /*{{{*/ { pkgAcquire::Item *const Owner; pkgAcquire::Worker *const Worker; diff --git a/methods/connect.cc b/methods/connect.cc index f3e199d0a..12847c594 100644 --- a/methods/connect.cc +++ b/methods/connect.cc @@ -85,7 +85,7 @@ static bool ConnectionAllowed(char const * const Service, std::string const &Hos /*}}}*/ // File Descriptor based Fd /*{{{*/ -struct FdFd : public MethodFd +struct FdFd final : public MethodFd { int fd = -1; int Fd() APT_OVERRIDE { return fd; } @@ -805,7 +805,7 @@ ResultState UnwrapSocks(std::string Host, int Port, URI Proxy, std::unique_ptr UnderlyingFd; gnutls_session_t session; diff --git a/methods/copy.cc b/methods/copy.cc index 82eed150c..44205e4cd 100644 --- a/methods/copy.cc +++ b/methods/copy.cc @@ -24,7 +24,7 @@ #include /*}}}*/ -class CopyMethod : public aptMethod +class CopyMethod final : public aptMethod { virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE; diff --git a/methods/file.cc b/methods/file.cc index b2fe133f2..0a76c0c94 100644 --- a/methods/file.cc +++ b/methods/file.cc @@ -27,7 +27,7 @@ #include /*}}}*/ -class FileMethod : public aptMethod +class FileMethod final : public aptMethod { virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE; diff --git a/methods/http.cc b/methods/http.cc index 4d0e60d93..1e76a1f57 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -279,7 +279,7 @@ CircleBuf::~CircleBuf() /*{{{*/ // UnwrapHTTPConnect - Does the HTTP CONNECT handshake /*{{{*/ // --------------------------------------------------------------------- /* Performs a TLS handshake on the socket */ -struct HttpConnectFd : public MethodFd +struct HttpConnectFd final : public MethodFd { std::unique_ptr UnderlyingFd; std::string Buffer; diff --git a/methods/http.h b/methods/http.h index cae579afe..5bfcbc8a2 100644 --- a/methods/http.h +++ b/methods/http.h @@ -90,7 +90,7 @@ class CircleBuf ~CircleBuf(); }; -struct HttpServerState: public ServerState +struct HttpServerState final : public ServerState { // This is the connection itself. Output is data FROM the server CircleBuf In; @@ -121,7 +121,7 @@ struct HttpServerState: public ServerState virtual ~HttpServerState() {Close();}; }; -class HttpMethod : public BaseHttpMethod +class HttpMethod final : public BaseHttpMethod { public: virtual void SendReq(FetchItem *Itm) APT_OVERRIDE; diff --git a/methods/rred.cc b/methods/rred.cc index aeefea5a2..bef2e969e 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -598,7 +598,7 @@ class Patch { }; #ifndef APT_EXCLUDE_RRED_METHOD_CODE -class RredMethod : public aptMethod { +class RredMethod final : public aptMethod { private: bool Debug; diff --git a/methods/store.cc b/methods/store.cc index 23d6b43d0..ed2eb3fe1 100644 --- a/methods/store.cc +++ b/methods/store.cc @@ -31,7 +31,7 @@ #include /*}}}*/ -class StoreMethod : public aptMethod +class StoreMethod final : public aptMethod { virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE; -- cgit v1.2.3-70-g09d2