diff --git a/bazaar/Functions4U/Bsdiff/bspatch.cpp b/bazaar/Functions4U/Bsdiff/bspatch.cpp index e76b423ea..bc8c88914 100644 --- a/bazaar/Functions4U/Bsdiff/bspatch.cpp +++ b/bazaar/Functions4U/Bsdiff/bspatch.cpp @@ -80,11 +80,10 @@ bool BSPatch(String oldfile, String newfile, String patchfile) //if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); /* Open patch file */ - if ( #ifdef PLATFORM_POSIX - (f = fopen(patchfile, "r")) == NULL) + if ((f = fopen(patchfile, "r")) == NULL) #else - (f = _wfopen(patchfile.ToWString(), L"rb")) == NULL) + if ((f = _wfopen(patchfile.ToWString(), L"rb")) == NULL) #endif return Err(Format(t_("fopen(%s)"), patchfile)); @@ -104,7 +103,8 @@ bool BSPatch(String oldfile, String newfile, String patchfile) /* Read header */ if (fread(header, 1, 32, f) < 32) { - if (feof(f)) + fclose(f); + if (feof(f)) return Err(t_("Corrupt patch")); return Err(Format(t_("fread(%s)"), patchfile)); } @@ -130,9 +130,11 @@ bool BSPatch(String oldfile, String newfile, String patchfile) (cpf = _wfopen(patchfile.ToWString(), L"rb")) == NULL) #endif return Err(Format(t_("fopen(%s)"), patchfile)); - if (fseeko(cpf, 32, SEEK_SET)) + if (fseeko(cpf, 32, SEEK_SET)) { + fclose(cpf); return Err(Format(t_("fseeko(%s, %lld)"), patchfile, (long long)32)); + } if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) return Err(Format(t_("BZ2_bzReadOpen, bz2err = %d"), cbz2err)); if ( @@ -160,11 +162,10 @@ bool BSPatch(String oldfile, String newfile, String patchfile) if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) return Err(Format(t_("BZ2_bzReadOpen, bz2err = %d"), ebz2err)); - if( #ifdef PLATFORM_POSIX - ((fd = open(oldfile, O_RDONLY, 0)) < 0) || + if (((fd = open(oldfile, O_RDONLY, 0)) < 0) || #else - ((fd = _wsopen(oldfile.ToWString(), O_RDONLY|O_BINARY, _SH_DENYNO, 0)) < 0) || + if (((fd = _wsopen(oldfile.ToWString(), O_RDONLY|O_BINARY, _SH_DENYNO, 0)) < 0) || #endif ((oldsize=lseek(fd,0,SEEK_END))==-1) || ((old=(u_char *)malloc(oldsize+1))==NULL) || @@ -232,11 +233,10 @@ bool BSPatch(String oldfile, String newfile, String patchfile) return Err(Format(t_("fclose(%s)"), patchfile)); /* Write the new file */ - if( #ifdef PLATFORM_POSIX - ((fd = open(newfile, O_CREAT|O_TRUNC|O_WRONLY, 0666)) < 0) || + if (((fd = open(newfile, O_CREAT|O_TRUNC|O_WRONLY, 0666)) < 0) || #else - ((fd = _wsopen(newfile.ToWString(), O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, _SH_DENYNO, _S_IREAD | _S_IWRITE)) < 0) || + if (((fd = _wsopen(newfile.ToWString(), O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, _SH_DENYNO, _S_IREAD | _S_IWRITE)) < 0) || #endif (write(fd,nnew,newsize)!=newsize) || (close(fd)==-1)) return Err(Format(t_("Impossible to open %s"), newfile)); diff --git a/bazaar/Functions4U/Functions4U.cpp b/bazaar/Functions4U/Functions4U.cpp index 8851fd522..2be18297d 100644 --- a/bazaar/Functions4U/Functions4U.cpp +++ b/bazaar/Functions4U/Functions4U.cpp @@ -985,7 +985,7 @@ String SeasonName(int iseason) { return iseason >= 0 && iseason < 4 ? season[iseason] : ""; } -int GetSeason(Date &date) { +int GetSeason(const Date &date) { return int((date.month - 1)/3.); } @@ -1001,7 +1001,7 @@ String BytesToString(uint64 _bytes, bool units) if (bytes >= 1024) { bytes /= 1024; if (bytes >= 1024) { - bytes /= 1024; + //bytes /= 1024; ret = Format("%.1f %s", _bytes/(1024*1024*1024*1024.), units ? "Tb" : ""); } else ret = Format("%.1f %s", _bytes/(1024*1024*1024.), units ? "Gb" : ""); @@ -1776,8 +1776,10 @@ int64 FindStringInFile(const char *file, const String text, int64 pos0) { int64 pos = 0; if (pos0 > 0) { pos = pos0; - if (0 == fseek(fp, long(pos0), SEEK_SET)) + if (0 == fseek(fp, long(pos0), SEEK_SET)) { + fclose(fp); return -2; + } } int i = 0, c; for (; (c = fgetc(fp)) != EOF; pos++) { @@ -1926,7 +1928,6 @@ bool FileDataArray::Init(String , FileDataArray &orig, FileDiffArray &diff) else fileCount--; break; - break; case 'p': SetLastError(t_("Problem found")); // To Fix //return false; @@ -2084,7 +2085,7 @@ bool operator<(const FileData& a, const FileData& b) return a.isFolder; } -bool CheckFileData(FileData &data, String &, String &, String &lowrelFileName, String &lowfileName, bool isFolder) { +bool CheckFileData(FileData &data, String &, String &, const String &lowrelFileName, const String &lowfileName, bool isFolder) { if (data.isFolder == isFolder) { if (ToLower(data.fileName) == lowfileName) { if (ToLower(data.relFilename) == lowrelFileName) @@ -2558,10 +2559,6 @@ String WideToString(LPCWSTR wcs, int len) { #if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64) -Dl::Dl() { - hinstLib = 0; -} - Dl::~Dl() { if (hinstLib) if (FreeLibrary(hinstLib) == 0) diff --git a/bazaar/Functions4U/Functions4U.h b/bazaar/Functions4U/Functions4U.h index c1c1bd048..55ac28c1a 100644 --- a/bazaar/Functions4U/Functions4U.h +++ b/bazaar/Functions4U/Functions4U.h @@ -294,8 +294,6 @@ template inline T BetweenVal(const T& val, const T& _min, const T& _max) { return max(_min, min(_max, val)); } -template -inline bool IsNAN(T val) {return std::isnan(val);} template inline T FixFloat(T val) { @@ -544,16 +542,15 @@ Vector GetDriveList(); class Dl { public: - Dl(); virtual ~Dl(); bool Load(const String &fileDll); void *GetFunction(const String &functionName); private: #if defined(PLATFORM_WIN32) - HINSTANCE hinstLib; + HINSTANCE hinstLib = 0; #else - void *hinstLib; + void *hinstLib = 0; #endif }; @@ -634,18 +631,6 @@ class ThreadSafe { ... };*/ -template -void LinSpaced(Range &v, int n, typename Range::value_type min, typename Range::value_type max) { - ASSERT(n > 0); - v.SetCount(n); - if (n == 1) - v[0] = min; - else { - typename Range::value_type d = (max - min)/(n - 1); - for (int i = 0; i < n; ++i) - v[i] = min + d*i; - } -} template static void ShuffleAscending(C &data, std::default_random_engine &generator) { @@ -701,7 +686,9 @@ bool EqualRatio(const T& a, const T& b, const T& ratio, const T& zero = 0) { template bool EqualDecimals(const T& a, const T& b, int numdecimals) { - return FormatDouble(a, numdecimals) == FormatDouble(b, numdecimals); + String sa = FormatDouble(a, numdecimals); + String sb = FormatDouble(a, numdecimals); + return sa == sb; } template @@ -907,7 +894,7 @@ class LocalProcessX { typedef LocalProcessX CLASSNAME; public: - LocalProcessX() {} + //LocalProcessX() {} virtual ~LocalProcessX() {Stop();} enum ProcessStatus {RUNNING = 1, STOP_OK = 0, STOP_TIMEOUT = -1, STOP_USER = -2, STOP_NORESPONSE = -3}; bool Start(const char *cmd, const char *envptr = 0, const char *dir = 0, double _refreshTime = -1, @@ -1145,6 +1132,14 @@ public: throw Exc(in->Str() + Format(t_("Bad %s '%s' in field #%d, line\n'%s'"), "integer", fields[i], i+1, line)); return res; } + bool IsInt(int i) const { + if (fields.IsEmpty()) + throw Exc(in->Str() + t_("No data available")); + if (IsNull(i)) + i = fields.GetCount()-1; + CheckId(i); + return !IsNull(ScanInt(fields[i])); + } double GetDouble(int i) const { if (fields.IsEmpty()) throw Exc(in->Str() + t_("No data available")); @@ -1157,6 +1152,10 @@ public: return res; } + bool IsEof() { + return in->IsEof(); + } + int size() const {return fields.GetCount();} int GetCount() const {return size();} bool IsEmpty() const {return size() == 0;} diff --git a/bazaar/Functions4U/QtfEquation.cpp b/bazaar/Functions4U/QtfEquation.cpp index 5aa1541d2..90b88f81e 100644 --- a/bazaar/Functions4U/QtfEquation.cpp +++ b/bazaar/Functions4U/QtfEquation.cpp @@ -25,8 +25,9 @@ String CParserPlus::ReadIdPlus() { Drawing EquationDraw::Text(String text, bool italic, int offsetX, int offsetY, double betw) { Font fnt; - int _pos1, _pos2; + int _pos1; if ((_pos1 = text.Find('_', 0)) >= 0) { + int _pos2; String sub = text.Right(text.GetCount()-_pos1-1); if ((_pos2 = sub.Find('_', 0)) >= 0) sub = sub.Left(_pos2) + ',' + sub.Right(sub.GetCount()-_pos2-1); @@ -444,7 +445,7 @@ Drawing DrawEquation(const String &str) { } else return equation.Exp(p); } - catch(CParser::Error e) { + catch(CParser::Error &e) { String res; res << "ERROR: " << e; return EquationDraw::Text(res); diff --git a/bazaar/Functions4U/StaticPlugin.cpp b/bazaar/Functions4U/StaticPlugin.cpp index 50d6d7713..760736b31 100644 --- a/bazaar/Functions4U/StaticPlugin.cpp +++ b/bazaar/Functions4U/StaticPlugin.cpp @@ -9,10 +9,6 @@ Array& StaticPlugin::Plugins() { return x; } -StaticPlugin::StaticPlugin() { - data = 0; -} - StaticPlugin::~StaticPlugin() { End(); } diff --git a/bazaar/Functions4U/StaticPlugin.h b/bazaar/Functions4U/StaticPlugin.h index c1821ac16..20f2eac4c 100644 --- a/bazaar/Functions4U/StaticPlugin.h +++ b/bazaar/Functions4U/StaticPlugin.h @@ -9,10 +9,10 @@ namespace Upp { class StaticPlugin { private: - void *data; + void *data = 0; String name; String type; - void *instance; + void *instance = 0; template static void *New() {return new T;} template static void Delete(void *p) {delete static_cast(p);} @@ -31,7 +31,6 @@ protected: static Upp::Array& Plugins(); public: - StaticPlugin(); virtual ~StaticPlugin(); void End();