diff options
author | David Kalnischkies <david@kalnischkies.de> | 2017-12-13 23:54:38 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2017-12-13 23:54:38 +0100 |
commit | 99813a2eaa7c0cce1d7d8c811827733ed66458de (patch) | |
tree | 61fe422eeca8c5bd5cb2de6060f11e71343d4602 /apt-pkg/contrib | |
parent | d30b30ad1e1ce434df84e15e2573c43ac152f9e3 (diff) | |
parent | 0b5e329a8ba2461ccb7017d3adfc972f9dccd830 (diff) |
Merge branch 'feature/happy-gcc'
Fixing various real and imagined bugs reported by gcc warnings
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 33 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.h | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.h | 14 | ||||
-rw-r--r-- | apt-pkg/contrib/hashsum_template.h | 8 | ||||
-rw-r--r-- | apt-pkg/contrib/macros.h | 1 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.cc | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.h | 7 | ||||
-rw-r--r-- | apt-pkg/contrib/netrc.cc | 14 | ||||
-rw-r--r-- | apt-pkg/contrib/progress.cc | 5 |
10 files changed, 49 insertions, 40 deletions
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<char **>(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; } /*}}}*/ 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<Configuration *>(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<char const * const>(memchr(buffer.get(), '\n', OutputSize)); + char const * const newline = static_cast<char const *>(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<unsigned char const *>(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<const unsigned char *>(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<const char *>(Data))); } inline bool Add(const char *Data) APT_NONNULL(2) - { return Add((const unsigned char *)Data, strlen(Data)); } + { return Add(reinterpret_cast<const unsigned char *>(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<const unsigned char *>(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/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 \ 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 <string> #include <errno.h> #include <stdlib.h> -#include <sys/mman.h> #include <unistd.h> #include <apti18n.h> @@ -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<unsigned long>::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 <string> +#include <limits> + +#include <sys/mman.h> #ifndef APT_8_CLEANER_HEADERS #include <apt-pkg/fileutl.h> @@ -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<unsigned long>::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;}; 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; } 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 <apt-pkg/error.h> #include <apt-pkg/progress.h> +#include <cmath> #include <cstring> #include <iostream> #include <string> @@ -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; |