diff options
| author | David Kalnischkies <david@kalnischkies.de> | 2024-12-26 20:46:23 +0000 |
|---|---|---|
| committer | David Kalnischkies <david@kalnischkies.de> | 2025-01-05 22:16:08 +0000 |
| commit | 1e2b5197ee350a36fbad006f198bbf8e9a5c8e53 (patch) | |
| tree | 79ddb6ec61fb442c43b17117f02fecf79f279d39 | |
| parent | 6828ae2c2f9268c8187f0fa91b3c464ed84a8476 (diff) | |
Drop the remaining usage of APT_ARRAY_SIZE
That macro is not that useful as it might perhaps once was. Lets prepare
dropping it now in favour of more standard ways of working with arrays
now.
| -rw-r--r-- | apt-pkg/contrib/macros.h | 5 | ||||
| -rw-r--r-- | apt-pkg/pkgcache.cc | 2 | ||||
| -rw-r--r-- | methods/gpgv.cc | 13 |
3 files changed, 7 insertions, 13 deletions
diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index e0c23b99b..807733927 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -17,10 +17,6 @@ #ifndef MACROS_H #define MACROS_H -/* Useful count macro, use on an array of things and it will return the - number of items in the array */ -#define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - // Flag Macros #define FLAG(f) (1L << (f)) #define SETFLAG(v,f) ((v) |= FLAG(f)) @@ -141,6 +137,7 @@ AptScopeWrapper(F) -> AptScopeWrapper<F>; #else #define APT_OVERRIDE /* no c++11 standard */ #endif +#define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #endif #endif #endif diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 57c6d2b22..1f5f12885 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -245,7 +245,7 @@ uint32_t pkgCache::CacheHash() XXH3_64bits_update(state, reinterpret_cast<const unsigned char *>(PACKAGE_VERSION), - APT_ARRAY_SIZE(PACKAGE_VERSION)); + strlen(PACKAGE_VERSION)); XXH3_64bits_update(state, reinterpret_cast<const unsigned char *>(&header), diff --git a/methods/gpgv.cc b/methods/gpgv.cc index 736cfbde2..8eda8d67f 100644 --- a/methods/gpgv.cc +++ b/methods/gpgv.cc @@ -68,7 +68,7 @@ struct Digest { } }; -static constexpr Digest Digests[] = { +static constexpr std::array<Digest,12> Digests = {{ {Digest::State::Untrusted, "Invalid digest"}, {Digest::State::Untrusted, "MD5"}, {Digest::State::Untrusted, "SHA1"}, @@ -81,17 +81,14 @@ static constexpr Digest Digests[] = { {Digest::State::Trusted, "SHA384"}, {Digest::State::Trusted, "SHA512"}, {Digest::State::Trusted, "SHA224"}, -}; +}}; -static Digest FindDigest(std::string const & Digest) +static Digest FindDigest(std::string const &Digest) { int id = atoi(Digest.c_str()); - if (id >= 0 && static_cast<unsigned>(id) < APT_ARRAY_SIZE(Digests)) - { + if (id >= 0 && static_cast<unsigned>(id) < Digests.size()) return Digests[id]; - } else { - return Digests[0]; - } + return Digests[0]; } struct Signer { |
