diff --git a/src/containers/picontainers.h b/src/containers/picontainers.h index ee122b17..119fe668 100755 --- a/src/containers/picontainers.h +++ b/src/containers/picontainers.h @@ -29,6 +29,25 @@ #include "picout.h" #include +#include +#ifndef PIP_MEMALIGN_BYTES +# define PIP_MEMALIGN_BYTES (sizeof(void*)*4) +#endif +#ifdef WINDOWS +# ifdef CC_GCC +# define amalloc(s) __mingw_aligned_malloc(s, PIP_MEMALIGN_BYTES) +# define afree(p) __mingw_aligned_free(p) +# else +# ifdef CC_VC +# define amalloc(s) _aligned_malloc(s, PIP_MEMALIGN_BYTES) +# define afree(p) _aligned_free(p) +# endif +# endif +#else +# define amalloc(s) aligned_alloc(PIP_MEMALIGN_BYTES, s) +# define afree(p) free(p) +#endif + template class PIP_EXPORT PIPair { public: diff --git a/src/containers/pideque.h b/src/containers/pideque.h index 49a19246..f1945ab2 100755 --- a/src/containers/pideque.h +++ b/src/containers/pideque.h @@ -306,7 +306,7 @@ public: PIDeque & enlarge(llong pid_size) {llong ns = size_s() + pid_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;} PIDeque & removeOne(const T & v) {for (size_t i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); return *this;} return *this;} - PIDeque & removeAll(const T & v) {for (llong i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;} + PIDeque & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(pid_size); ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;} PIDeque & push_back(const T & v) {alloc(pid_size + 1, true); PIINTROSPECTION_CONTAINER_USED(sizeof(T)); elementNew(pid_data + pid_start + pid_size - 1, v); return *this;} PIDeque & append(const T & v) {return push_back(v);} @@ -416,7 +416,7 @@ private: } }*/ //printf("(%p) check move st=%d sz=%d rs=%d\n", this, pid_start, pid_size, pid_rsize); - if (pid_start < pid_size + pid_size || pid_start > pid_rsize - pid_size - pid_size) { + if (pid_start < ssize_t(pid_size + pid_size) || pid_start > (ssize_t(pid_rsize) - ssize_t(pid_size) - ssize_t(pid_size))) { ssize_t ns = (pid_rsize - pid_size) / 2; if (pid_start != ns) { //printf("(%p) move %d -> %d\n", this, pid_start, ns); diff --git a/src/containers/pivector.h b/src/containers/pivector.h index c2b2f67e..da2152e6 100755 --- a/src/containers/pivector.h +++ b/src/containers/pivector.h @@ -274,7 +274,7 @@ public: PIVector & enlarge(llong piv_size) {llong ns = size_s() + piv_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;} PIVector & removeOne(const T & v) {for (size_t i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); return *this;} return *this;} - PIVector & removeAll(const T & v) {for (llong i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;} + PIVector & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(piv_size); ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;} PIVector & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;} PIVector & append(const T & v) {return push_back(v);} diff --git a/src/core/pibase.h b/src/core/pibase.h index 5b5b3055..8032c015 100644 --- a/src/core/pibase.h +++ b/src/core/pibase.h @@ -97,7 +97,6 @@ #ifdef WINDOWS # include # include -# include # ifdef CC_VC # define SHUT_RDWR 2 # pragma comment(lib, "Ws2_32.lib") @@ -113,24 +112,6 @@ inline int random() {return rand();} #endif -#ifndef PIP_MEMALIGN_BYTES -# define PIP_MEMALIGN_BYTES (sizeof(void*)*4) -#endif -#ifdef WINDOWS -# ifdef CC_GCC -# define amalloc(s) __mingw_aligned_malloc(s, PIP_MEMALIGN_BYTES) -# define afree(p) __mingw_aligned_free(p) -# else -# ifdef CC_VC -# define amalloc(s) _aligned_malloc(s, PIP_MEMALIGN_BYTES) -# define afree(p) _aligned_free(p) -# endif -# endif -#else -# define amalloc(s) aligned_alloc(PIP_MEMALIGN_BYTES, s) -# define afree(p) free(p) -#endif - #ifdef ANDROID # define tcdrain(fd) ioctl(fd, TCSBRK, 1) //inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;} @@ -165,9 +146,9 @@ # pragma GCC diagnostic ignored "-Waggressive-loop-optimizations" # endif # pragma GCC diagnostic ignored "-Wformat" -# pragma GCC diagnostic ignored "-Wformat-extra-args" +//# pragma GCC diagnostic ignored "-Wformat-extra-args" # pragma GCC diagnostic ignored "-Wstrict-aliasing" -# pragma GCC diagnostic ignored "-Wsign-compare" +//# pragma GCC diagnostic ignored "-Wsign-compare" # endif # ifdef ANDROID # pragma GCC diagnostic ignored "-Wunused-parameter" @@ -414,10 +395,15 @@ template inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, size // specialization template<> inline ushort piLetobe(const ushort & v) {return (v << 8) | (v >> 8);} template<> inline uint piLetobe(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);} -template<> inline float piLetobe(const float & f) { - uint v = *((uint *)&f); - v = (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000); - return *((float *)&v); +template<> inline float piLetobe(const float & v) { + union _pletobe_f { + _pletobe_f(const float &f_) {f = f_;} + float f; + uint v; + }; + _pletobe_f a(v); + a.v = (a.v >> 24) | ((a.v >> 8) & 0xFF00) | ((a.v << 8) & 0xFF0000) | ((a.v << 24) & 0xFF000000); + return a.f; } DEPRECATED inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);} diff --git a/src/core/piinit.cpp b/src/core/piinit.cpp index 7a85de9a..d5df2292 100644 --- a/src/core/piinit.cpp +++ b/src/core/piinit.cpp @@ -48,6 +48,9 @@ # include # include #endif +#ifdef CC_GCC +# include +#endif /* #ifdef WINDOWS # include diff --git a/src/core/pipropertystorage.cpp b/src/core/pipropertystorage.cpp index 351e4f8f..e3e2e173 100644 --- a/src/core/pipropertystorage.cpp +++ b/src/core/pipropertystorage.cpp @@ -2,7 +2,7 @@ bool PIPropertyStorage::isPropertyExists(const PIString & _name) const { - for (int i = 0; i < props.size(); ++i) + for (uint i = 0; i < props.size(); ++i) if (props[i].name == _name) return true; return false; @@ -10,7 +10,7 @@ bool PIPropertyStorage::isPropertyExists(const PIString & _name) const { void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) { - for (int i = 0; i < props.size(); ++i) + for (uint i = 0; i < props.size(); ++i) if (props[i].name == p.name) { props[i] = p; return; @@ -20,7 +20,7 @@ void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) { void PIPropertyStorage::removeProperty(const PIString & _name) { - for (int i = 0; i < props.size(); ++i) + for (uint i = 0; i < props.size(); ++i) if (props[i].name == _name) { props.remove(i); return; @@ -29,7 +29,7 @@ void PIPropertyStorage::removeProperty(const PIString & _name) { void PIPropertyStorage::removePropertiesByFlag(int flag) { - for (int i = 0; i < props.size(); ++i) + for (int i = 0; i < props.size_s(); ++i) if ((props[i].flags & flag) == flag) { props.remove(i); --i; @@ -43,7 +43,7 @@ void PIPropertyStorage::updateProperties(const PIVector PIDir::entries() { PIFile::FileInfo fi; DWORD ll = GetLogicalDriveStrings(1023, letters); PIString clet; - for (int i = 0; i < ll; ++i) { + for (DWORD i = 0; i < ll; ++i) { if (letters[i] == '\0') { clet.resize(2); fi.path = clet; diff --git a/src/io/pifiletransfer.cpp b/src/io/pifiletransfer.cpp index 1803bc2a..707591b3 100644 --- a/src/io/pifiletransfer.cpp +++ b/src/io/pifiletransfer.cpp @@ -55,7 +55,7 @@ bool PIFileTransfer::send(PIVector entries) { scanning = false; scan_dir.up(); //piCout << "files rel to" << d.absolutePath(); - for (int j = 0; j < fls.size(); j++) { + for (uint j = 0; j < fls.size(); j++) { allEntries << PFTFileInfo(fls[j]); allEntries.back().dest_path = scan_dir.relative(fls[j].path); //piCout << " abs path" << fls[j].path; diff --git a/src/io/pipeer.cpp b/src/io/pipeer.cpp index c86f7b8f..168f5db6 100755 --- a/src/io/pipeer.cpp +++ b/src/io/pipeer.cpp @@ -134,7 +134,7 @@ PIString PIPeer::PeerInfo::fastestAddress() const { REGISTER_DEVICE(PIPeer) -PIPeer::PIPeer(const PIString & n): PIIODevice(), eth_tcp_srv(PIEthernet::TCP_Server), eth_tcp_cli(PIEthernet::TCP_Client), diag_s(false), diag_d(false) { +PIPeer::PIPeer(const PIString & n): PIIODevice(), inited__(false), eth_tcp_srv(PIEthernet::TCP_Server), eth_tcp_cli(PIEthernet::TCP_Client), diag_s(false), diag_d(false) { //piCout << " PIPeer" << uint(this); destroyed = false; setDebug(false); @@ -429,7 +429,7 @@ void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) { dataReceivedEvent(from, data); if (trust_peer.isEmpty() || trust_peer == from) { read_buffer_mutex.lock(); - if (read_buffer.size() < read_buffer_size) read_buffer.enqueue(data); + if (read_buffer.size_s() < read_buffer_size) read_buffer.enqueue(data); read_buffer_mutex.unlock(); } } diff --git a/src/io/pipeer.h b/src/io/pipeer.h index 989f15d0..197401e6 100755 --- a/src/io/pipeer.h +++ b/src/io/pipeer.h @@ -195,6 +195,7 @@ private: // Data packet: 4, from, to, ticks, data_size, data protected: + bool inited__; //for internal use PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex; private: diff --git a/src/math/picrypt.cpp b/src/math/picrypt.cpp index 625fd8ac..7c8a4337 100644 --- a/src/math/picrypt.cpp +++ b/src/math/picrypt.cpp @@ -28,7 +28,7 @@ const char hash_def_key[] = "_picrypt_"; PICrypt::PICrypt() { #ifdef PIP_CRYPT - sodium_init(); + if (!sodium_init()) piCout << "[PICrypt]" << "Error while initialize sodium!"; nonce_.resize(crypto_secretbox_NONCEBYTES); key_.resize(crypto_secretbox_KEYBYTES); randombytes_buf(key_.data(), key_.size()); @@ -77,7 +77,7 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) { if (key.size() != crypto_secretbox_KEYBYTES) key.resize(crypto_secretbox_KEYBYTES, ' '); //return PIByteArray(); - sodium_init(); + if (!sodium_init()) return retba; PIByteArray n; retba.resize(data.size() + crypto_secretbox_MACBYTES); n.resize(crypto_secretbox_NONCEBYTES); @@ -123,7 +123,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo if (ok) *ok = false; return PIByteArray(); } - sodium_init(); + if (!sodium_init()) return retba; PIByteArray n; n.resize(crypto_secretbox_NONCEBYTES); retba.resize(crypt_data.size() - n.size() - crypto_secretbox_MACBYTES); @@ -144,7 +144,7 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bo PIByteArray PICrypt::hash(const PIString & secret) { PIByteArray hash; #ifdef PIP_CRYPT - sodium_init(); + if (!sodium_init()) return hash; hash.resize(crypto_generichash_BYTES); PIByteArray s(secret.data(), secret.size()); crypto_generichash(hash.data(), hash.size(), s.data(), s.size(), (const uchar*)hash_def_key, sizeof(hash_def_key) - 1); @@ -159,7 +159,7 @@ ullong PICrypt::shorthash(const PIString& s, PIByteArray key) { ullong hash = 0; #ifdef PIP_CRYPT if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size"; - sodium_init(); + if (!sodium_init()) return hash; if (key.size() != crypto_shorthash_KEYBYTES) { piCout << "[PICrypt]" << "invalid key size" << key.size() << ", shoud be" << crypto_shorthash_KEYBYTES << ", filled zeros"; key.resize(crypto_shorthash_KEYBYTES, 0); @@ -176,7 +176,7 @@ ullong PICrypt::shorthash(const PIString& s, PIByteArray key) { PIByteArray PICrypt::generateKey() { PIByteArray hash; #ifdef PIP_CRYPT - sodium_init(); + if (!sodium_init()) return hash; hash.resize(crypto_secretbox_KEYBYTES); randombytes_buf(hash.data(), hash.size()); #else @@ -186,7 +186,7 @@ PIByteArray PICrypt::generateKey() { } -int PICrypt::sizeKey() { +size_t PICrypt::sizeKey() { #ifdef PIP_CRYPT return crypto_secretbox_KEYBYTES; #else @@ -196,7 +196,7 @@ int PICrypt::sizeKey() { } -int PICrypt::sizeCrypt() { +size_t PICrypt::sizeCrypt() { #ifdef PIP_CRYPT return crypto_secretbox_MACBYTES + crypto_secretbox_NONCEBYTES; #else diff --git a/src/math/picrypt.h b/src/math/picrypt.h index 8c031871..cb7bdb1e 100644 --- a/src/math/picrypt.h +++ b/src/math/picrypt.h @@ -61,10 +61,10 @@ public: static PIByteArray generateKey(); //! Returns key size - static int sizeKey(); + static size_t sizeKey(); //! Returns size which be added to data size in encryption process - static int sizeCrypt(); + static size_t sizeCrypt(); private: PIByteArray nonce_, key_; diff --git a/src/math/pimathvector.h b/src/math/pimathvector.h index d743e52a..9e2af539 100644 --- a/src/math/pimathvector.h +++ b/src/math/pimathvector.h @@ -115,7 +115,7 @@ public: static _CVector filled(const Type & v) {_CVector vv; PIMV_FOR(i, 0) vv[i] = v; return vv;} private: - void resize(const Type & new_value = Type()) {for (int i = 0; i < Size; ++i) c[i] = new_value;} + void resize(const Type & new_value = Type()) {for (uint i = 0; i < Size; ++i) c[i] = new_value;} Type c[Size]; diff --git a/src/system/pisysteminfo.cpp b/src/system/pisysteminfo.cpp index 7b50f1d6..a9187643 100644 --- a/src/system/pisysteminfo.cpp +++ b/src/system/pisysteminfo.cpp @@ -42,7 +42,7 @@ PIStringList PISystemInfo::mountRoots() { char letters[1024]; DWORD ll = GetLogicalDriveStrings(1023, letters); PIString clet; - for (int i = 0; i < ll; ++i) { + for (uint i = 0; i < ll; ++i) { if (letters[i] == '\0') { if (clet.size_s() > 2) ret << clet.cutRight(1); clet.clear(); @@ -90,7 +90,7 @@ PIVector PISystemInfo::mountInfo() { char letters[1024], volname[1024], volfs[1024]; DWORD ll = GetLogicalDriveStrings(1023, letters); PIString clet; - for (int i = 0; i < ll; ++i) { + for (DWORD i = 0; i < ll; ++i) { if (letters[i] == '\0') { if (GetVolumeInformation(clet.data(), volname, 1023, 0, 0, 0, volfs, 1023)) { m.mount_point = clet; diff --git a/src/system/pisystemmonitor.cpp b/src/system/pisystemmonitor.cpp index 4830d8bb..67adb4b6 100755 --- a/src/system/pisystemmonitor.cpp +++ b/src/system/pisystemmonitor.cpp @@ -152,10 +152,10 @@ void PISystemMonitor::run() { THREADENTRY32 thread; thread.dwSize = sizeof(THREADENTRY32); if (Thread32First(snap, &thread) == TRUE) { - if (thread.th32OwnerProcessID == pID_) + if (thread.th32OwnerProcessID == DWORD(pID_)) ++thcnt; while (Thread32Next(snap, &thread) == TRUE) { - if (thread.th32OwnerProcessID == pID_) + if (thread.th32OwnerProcessID == DWORD(pID_)) ++thcnt; } } diff --git a/utils/system_daemon/daemon.cpp b/utils/system_daemon/daemon.cpp index 3c5f4283..328890fb 100644 --- a/utils/system_daemon/daemon.cpp +++ b/utils/system_daemon/daemon.cpp @@ -254,7 +254,7 @@ void Daemon::TileFileProgress::tileEvent(PIScreenTile * t, TileEvent e) { -Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) { +Daemon::Daemon(): PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) { // setName("Daemon"); dtimer.setName("__S__Daemon_timer"); mode = rmNone; diff --git a/utils/system_daemon/daemon.h b/utils/system_daemon/daemon.h index c0aa9738..9ba952f2 100644 --- a/utils/system_daemon/daemon.h +++ b/utils/system_daemon/daemon.h @@ -182,7 +182,6 @@ private: void requestChDir(const PIString & d); void sendDirToRemote(Remote * r); - bool inited__; mutable PIStringList available_daemons; PITimer dtimer; PIString conn_name;