From bb3a0325bf6b5c6c7cd076ba8a44d9d3eba0902b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Dec 2017 12:17:25 +0100 Subject: explicitly name token in auth.conf parsing error Reported-By: gcc -Wsign-promo --- apt-pkg/contrib/netrc.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc index 27511d413..ed8b2aa88 100644 --- a/apt-pkg/contrib/netrc.cc +++ b/apt-pkg/contrib/netrc.cc @@ -127,8 +127,18 @@ bool MaybeAddAuth(FileFd &NetRCFile, URI &Uri) return true; } else if (Debug) - std::clog << "MaybeAddAuth: Found no matching host (syntax error: " << active_token << ") for " - << (std::string)Uri << " from " << NetRCFile.Name() << std::endl; + { + std::clog << "MaybeAddAuth: Found no matching host (syntax error: token:"; + switch (active_token) + { + case NO: std::clog << "NO"; break; + case MACHINE: std::clog << "MACHINE"; break; + case GOOD_MACHINE: std::clog << "GOOD_MACHINE"; break; + case LOGIN: std::clog << "LOGIN"; break; + case PASSWORD: std::clog << "PASSWORD"; break; + } + std::clog << ") for " << (std::string)Uri << " from " << NetRCFile.Name() << std::endl; + } return false; } -- cgit v1.2.3 From 5d5ca1aac76448cdfd16972090d246c44671dce6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Dec 2017 12:51:26 +0100 Subject: deprecate the single-line deprecation ignoring macro gcc has problems understanding this construct and additionally thinks it would produce multiple lines and stuff, so to keep using it isn't really worth it for the few instances we have: We can just write the long form there which works better. Reported-By: gcc Gbp-Dch: Ignore --- apt-pkg/contrib/macros.h | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index abf99f7a2..57d3f6c22 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -143,6 +143,7 @@ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define APT_IGNORE_DEPRECATED_POP \ _Pragma("GCC diagnostic pop") + /* gcc has various problems with this shortcut, so prefer the long form */ #define APT_IGNORE_DEPRECATED(XXX) \ APT_IGNORE_DEPRECATED_PUSH \ XXX \ -- cgit v1.2.3 From 957381a0d26ec11a172ebfc64f892d1b31f0c193 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Dec 2017 13:26:38 +0100 Subject: convert various c-style casts to C++-style gcc was warning about ignored type qualifiers for all of them due to the last 'const', so dropping that and converting to static_cast in the process removes the here harmless warning to avoid hidden real issues in them later on. Reported-By: gcc Gbp-Dch: Ignore --- apt-pkg/contrib/configuration.h | 2 +- apt-pkg/contrib/fileutl.cc | 2 +- apt-pkg/contrib/hashes.h | 14 +++++++------- apt-pkg/contrib/hashsum_template.h | 8 ++++---- apt-pkg/contrib/mmap.cc | 3 +-- apt-pkg/contrib/mmap.h | 7 +++++-- 6 files changed, 19 insertions(+), 17 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 8d0835cf5..73f7acb81 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -66,7 +66,7 @@ class Configuration Item *Lookup(const char *Name,const bool &Create); inline const Item *Lookup(const char *Name) const { - return ((Configuration *)this)->Lookup(Name,false); + return const_cast(this)->Lookup(Name,false); } public: diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 6cc7414b0..d3764d003 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1107,7 +1107,7 @@ public: } unsigned long long const OutputSize = std::min(Size, buffer.size()); - char const * const newline = static_cast(memchr(buffer.get(), '\n', OutputSize)); + char const * const newline = static_cast(memchr(buffer.get(), '\n', OutputSize)); // Read until end of line or up to Size bytes from the buffer. unsigned long long actualread = buffer.read(To, (newline != nullptr) diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index 11521008a..dc91c1dd3 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -197,7 +197,7 @@ class Hashes bool Add(const unsigned char * const Data, unsigned long long const Size) APT_NONNULL(2); APT_DEPRECATED_MSG("Construct accordingly instead of choosing hashes while adding") bool Add(const unsigned char * const Data, unsigned long long const Size, unsigned int const Hashes) APT_NONNULL(2); inline bool Add(const char * const Data) APT_NONNULL(2) - {return Add((unsigned char const * const)Data,strlen(Data));}; + {return Add(reinterpret_cast(Data),strlen(Data));}; inline bool Add(const unsigned char * const Beg,const unsigned char * const End) APT_NONNULL(2,3) {return Add(Beg,End-Beg);}; @@ -227,12 +227,12 @@ APT_IGNORE_DEPRECATED_POP private: APT_HIDDEN APT_PURE inline unsigned int boolsToFlag(bool const addMD5, bool const addSHA1, bool const addSHA256, bool const addSHA512) { - unsigned int Hashes = ~0; - if (addMD5 == false) Hashes &= ~MD5SUM; - if (addSHA1 == false) Hashes &= ~SHA1SUM; - if (addSHA256 == false) Hashes &= ~SHA256SUM; - if (addSHA512 == false) Hashes &= ~SHA512SUM; - return Hashes; + unsigned int hashes = ~0; + if (addMD5 == false) hashes &= ~MD5SUM; + if (addSHA1 == false) hashes &= ~SHA1SUM; + if (addSHA256 == false) hashes &= ~SHA256SUM; + if (addSHA512 == false) hashes &= ~SHA512SUM; + return hashes; } public: diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h index 2594f6aeb..33e096b79 100644 --- a/apt-pkg/contrib/hashsum_template.h +++ b/apt-pkg/contrib/hashsum_template.h @@ -123,17 +123,17 @@ class SummationImplementation public: virtual bool Add(const unsigned char *inbuf, unsigned long long inlen) APT_NONNULL(2) = 0; inline bool Add(const char *inbuf, unsigned long long const inlen) APT_NONNULL(2) - { return Add((const unsigned char *)inbuf, inlen); } + { return Add(reinterpret_cast(inbuf), inlen); } inline bool Add(const unsigned char *Data) APT_NONNULL(2) - { return Add(Data, strlen((const char *)Data)); } + { return Add(Data, strlen(reinterpret_cast(Data))); } inline bool Add(const char *Data) APT_NONNULL(2) - { return Add((const unsigned char *)Data, strlen(Data)); } + { return Add(reinterpret_cast(Data), strlen(Data)); } inline bool Add(const unsigned char *Beg, const unsigned char *End) APT_NONNULL(2,3) { return Add(Beg, End - Beg); } inline bool Add(const char *Beg, const char *End) APT_NONNULL(2,3) - { return Add((const unsigned char *)Beg, End - Beg); } + { return Add(reinterpret_cast(Beg), End - Beg); } bool AddFD(int Fd, unsigned long long Size = 0); bool AddFD(FileFd &Fd, unsigned long long Size = 0); diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 100796cdf..bfded21e2 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -415,7 +414,7 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize) unsigned long DynamicMMap::WriteString(const char *String, unsigned long Len) { - if (Len == (unsigned long)-1) + if (Len == std::numeric_limits::max()) Len = strlen(String); _error->PushToStack(); diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h index df02b1b85..c194de534 100644 --- a/apt-pkg/contrib/mmap.h +++ b/apt-pkg/contrib/mmap.h @@ -26,6 +26,9 @@ #define PKGLIB_MMAP_H #include +#include + +#include #ifndef APT_8_CLEANER_HEADERS #include @@ -65,7 +68,7 @@ class MMap inline void *Data() {return Base;}; inline unsigned long long Size() {return iSize;}; inline void AddSize(unsigned long long const size) {iSize += size;}; - inline bool validData() const { return Base != (void *)-1 && Base != 0; }; + inline bool validData() const { return Base != MAP_FAILED && Base != 0; }; // File manipulators bool Sync(); @@ -104,7 +107,7 @@ class DynamicMMap : public MMap // Allocation unsigned long RawAllocate(unsigned long long Size,unsigned long Aln = 0); unsigned long Allocate(unsigned long ItemSize); - unsigned long WriteString(const char *String,unsigned long Len = (unsigned long)-1); + unsigned long WriteString(const char *String,unsigned long Len = std::numeric_limits::max()); inline unsigned long WriteString(const std::string &S) {return WriteString(S.c_str(),S.length());}; void UsePools(Pool &P,unsigned int Count) {Pools = &P; PoolCount = Count;}; -- cgit v1.2.3 From 1adcf56bec7d2127d83aa423916639740fe8e586 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Dec 2017 21:39:16 +0100 Subject: avoid some useless casts reported by -Wuseless-cast The casts are useless, but the reports show some where we can actually improve the code by replacing them with better alternatives like converting whatever int type into a string instead of casting to a specific one which might in the future be too small. Reported-By: gcc -Wuseless-cast --- apt-pkg/contrib/cdromutl.cc | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 93bfb9f42..7ae54060a 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -105,13 +105,14 @@ bool UnmountCdrom(string Path) } else { - const char *Args[10]; - Args[0] = "umount"; - Args[1] = Path.c_str(); - Args[2] = 0; - execvp(Args[0],(char **)Args); + const char * const Args[] = { + "umount", + Path.c_str(), + nullptr + }; + execvp(Args[0], const_cast(Args)); _exit(100); - } + } } // if it can not be umounted, give it a bit more time @@ -222,15 +223,13 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) std::string S; if (Version <= 1) - { - strprintf(S, "%lu", (unsigned long)Dir->d_ino); - } + S = std::to_string(Dir->d_ino); else { struct stat Buf; if (fstatat(dirfd, Dir->d_name, &Buf, 0) != 0) continue; - strprintf(S, "%lu", (unsigned long)Buf.st_mtime); + S = std::to_string(Buf.st_mtime); } Hash.Add(S.c_str()); @@ -246,21 +245,17 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) return _error->Errno("statfs",_("Failed to stat the cdrom")); // We use a kilobyte block size to avoid overflow - if (writable_media) - { - strprintf(S, "%lu", (unsigned long)(Buf.f_blocks*(Buf.f_bsize/1024))); - } else { - strprintf(S, "%lu %lu", (unsigned long)(Buf.f_blocks*(Buf.f_bsize/1024)), - (unsigned long)(Buf.f_bfree*(Buf.f_bsize/1024))); - } - Hash.Add(S.c_str()); + S = std::to_string(Buf.f_blocks * (Buf.f_bsize / 1024)); + if (writable_media == false) + S.append(" ").append(std::to_string(Buf.f_bfree * (Buf.f_bsize / 1024))); + Hash.Add(S.c_str(), S.length()); strprintf(S, "-%u", Version); } else strprintf(S, "-%u.debug", Version); closedir(D); - Res = Hash.Result().Value() + S; + Res = Hash.Result().Value().append(std::move(S)); return true; } /*}}}*/ -- cgit v1.2.3 From 0b5e329a8ba2461ccb7017d3adfc972f9dccd830 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Dec 2017 21:51:52 +0100 Subject: deal with floats without old-style cast We have no speed problem with handling floats/doubles in our progress handling, but that shouldn't prevent us from cleaning up the handling slightly to avoid unclean casting to ints. Reported-By: gcc -Wdouble-promotion -Wold-style-cast --- apt-pkg/contrib/progress.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc index 7c5b15e6b..5499f0946 100644 --- a/apt-pkg/contrib/progress.cc +++ b/apt-pkg/contrib/progress.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -44,7 +45,7 @@ void OpProgress::Progress(unsigned long long Cur) if (Total == 0 || Size == 0 || SubTotal == 0) Percent = 0; else - Percent = (Current + Cur/((float)SubTotal)*Size)*100.0/Total; + Percent = (Current + Cur/((double)SubTotal)*Size)*100.0/Total; Update(); } /*}}}*/ @@ -106,7 +107,7 @@ bool OpProgress::CheckChange(float Interval) return true; } - if ((int)LastPercent == (int)Percent) + if (std::lround(LastPercent) == std::lround(Percent)) return false; LastPercent = Percent; -- cgit v1.2.3