From a393f93ee1ea37dd73d298cc29c8f3f1a612f41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Mon, 7 Nov 2016 13:07:46 +0000 Subject: [PATCH] pvs fix warnings git-svn-id: svn://db.shs.com.ru/pip@280 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/code/picodeparser.cpp | 1 + src/console/piconsole.cpp | 78 ++++++++++++++--------------- src/console/piconsole.h | 2 + src/console/pikbdlistener.cpp | 8 +-- src/console/pikbdlistener.h | 6 +-- src/containers/pideque.h | 4 +- src/containers/pivector.h | 4 +- src/core/pibytearray.h | 3 +- src/core/picout.cpp | 2 +- src/core/pistatemachine.h | 4 +- src/core/pivariant.cpp | 12 ++++- src/core/pivariant.h | 2 + src/io/piconfig.h | 2 +- src/io/pifile.cpp | 5 +- src/io/pipacketextractor.h | 1 - src/io/piusb.cpp | 2 - src/math/pievaluator.cpp | 1 - src/math/pievaluator.h | 4 +- src/math/pifixedpoint.h | 2 +- src/system/piprocess.cpp | 3 +- utils/code_model_generator/main.cpp | 2 +- 21 files changed, 84 insertions(+), 64 deletions(-) diff --git a/src/code/picodeparser.cpp b/src/code/picodeparser.cpp index 41fa92c4..2a626881 100755 --- a/src/code/picodeparser.cpp +++ b/src/code/picodeparser.cpp @@ -170,6 +170,7 @@ void PICodeParser::clear() { cur_namespace.clear(); main_file.clear(); evaluator.clearCustomVariables(); + cur_def_vis = Global; defines << Define("PICODE", "") << custom_defines; } diff --git a/src/console/piconsole.cpp b/src/console/piconsole.cpp index 2052f4d2..d1ffeb21 100644 --- a/src/console/piconsole.cpp +++ b/src/console/piconsole.cpp @@ -480,51 +480,51 @@ void PIConsole::run() { toUpperLeft(); if (max_y < cvars.size()) max_y = cvars.size(); j = 0; - piForeachC (Variable & tv, cvars) { + piForeachC (Variable & tv_, cvars) { if (j > height - 3) continue; j++; moveRight(cx); - if (tv.type == 15) { + if (tv_.type == 15) { newLine(); continue; } - moveRight(tv.offset); + moveRight(tv_.offset); const void * ptr = 0; - if (tv.remote) { - if (tv.type == 0) { + if (tv_.remote) { + if (tv_.type == 0) { rstr.clear(); - rba = tv.rdata; + rba = tv_.rdata; rba >> rstr; rstr.trim(); ptr = &rstr; } else - ptr = tv.rdata.data(); + ptr = tv_.rdata.data(); } else - ptr = tv.ptr; - switch (tv.type) { - case 0: clen = printValue(ptr != 0 ? *(const PIString*)ptr : PIString(), tv.format); break; - case 1: clen = printValue(ptr != 0 ? *(const bool*)ptr : false, tv.format); break; - case 2: clen = printValue(ptr != 0 ? *(const int*)ptr : 0, tv.format); break; - case 3: clen = printValue(ptr != 0 ? *(const long*)ptr : 0l, tv.format); break; - case 4: clen = printValue(ptr != 0 ? *(const char*)ptr : char(0), tv.format); break; - case 5: clen = printValue(ptr != 0 ? *(const float*)ptr : 0.f, tv.format); break; - case 6: clen = printValue(ptr != 0 ? *(const double*)ptr : 0., tv.format); break; - case 7: clen = printValue(ptr != 0 ? *(const short*)ptr : short(0), tv.format); break; - case 8: clen = printValue(ptr != 0 ? *(const uint*)ptr : 0u, tv.format); break; - case 9: clen = printValue(ptr != 0 ? *(const ulong*)ptr : 0ul, tv.format); break; - case 10: clen = printValue(ptr != 0 ? *(const ushort*)ptr : ushort(0), tv.format); break; - case 11: clen = printValue(ptr != 0 ? *(const uchar*)ptr : uchar(0), tv.format); break; - case 12: clen = printValue(ptr != 0 ? *(const llong*)ptr : 0l, tv.format); break; - case 13: clen = printValue(ptr != 0 ? *(const ullong*)ptr: 0ull, tv.format); break; - case 20: clen = printValue(ptr != 0 ? *(const PISystemTime*)ptr: PISystemTime(), tv.format); break; - case 14: clen = printValue(bitsValue(ptr, tv.bitFrom, tv.bitCount), tv.format); break; + ptr = tv_.ptr; + switch (tv_.type) { + case 0: clen = printValue(ptr != 0 ? *(const PIString*)ptr : PIString(), tv_.format); break; + case 1: clen = printValue(ptr != 0 ? *(const bool*)ptr : false, tv_.format); break; + case 2: clen = printValue(ptr != 0 ? *(const int*)ptr : 0, tv_.format); break; + case 3: clen = printValue(ptr != 0 ? *(const long*)ptr : 0l, tv_.format); break; + case 4: clen = printValue(ptr != 0 ? *(const char*)ptr : char(0), tv_.format); break; + case 5: clen = printValue(ptr != 0 ? *(const float*)ptr : 0.f, tv_.format); break; + case 6: clen = printValue(ptr != 0 ? *(const double*)ptr : 0., tv_.format); break; + case 7: clen = printValue(ptr != 0 ? *(const short*)ptr : short(0), tv_.format); break; + case 8: clen = printValue(ptr != 0 ? *(const uint*)ptr : 0u, tv_.format); break; + case 9: clen = printValue(ptr != 0 ? *(const ulong*)ptr : 0ul, tv_.format); break; + case 10: clen = printValue(ptr != 0 ? *(const ushort*)ptr : ushort(0), tv_.format); break; + case 11: clen = printValue(ptr != 0 ? *(const uchar*)ptr : uchar(0), tv_.format); break; + case 12: clen = printValue(ptr != 0 ? *(const llong*)ptr : 0l, tv_.format); break; + case 13: clen = printValue(ptr != 0 ? *(const ullong*)ptr: 0ull, tv_.format); break; + case 20: clen = printValue(ptr != 0 ? *(const PISystemTime*)ptr: PISystemTime(), tv_.format); break; + case 14: clen = printValue(bitsValue(ptr, tv_.bitFrom, tv_.bitCount), tv_.format); break; } - if (clen + tv.offset < (uint)col_wid) { + if (clen + tv_.offset < (uint)col_wid) { PIString ts = PIString( #if defined(QNX) || defined(FREE_BSD) - col_wid - clen - tv.offset - 1, ' '); + col_wid - clen - tv_.offset - 1, ' '); #else - col_wid - clen - tv.offset, ' '); + col_wid - clen - tv_.offset, ' '); #endif printf("%s", ts.data()); } @@ -575,10 +575,10 @@ void PIConsole::fillLabels() { if (int(j) > height - 3) continue; if (max_y < j) max_y = j; moveRight(cx); - Variable & tv(cvars[j]); + Variable & tv_(cvars[j]); cvars[j].nx = cx; cvars[j].ny = cy; - if (tv.name.isEmpty()) { + if (tv_.name.isEmpty()) { cvars[j].offset = 0; clearLine(); newLine(); @@ -586,33 +586,33 @@ void PIConsole::fillLabels() { continue; } clearLine(); - //piCout << tv.name << tv.type << tv.ptr; - if (tv.type == 15) { + //piCout << tv_.name << tv_.type << tv_.ptr; + if (tv_.type == 15) { cvars[j].offset = cvars[j].name.length(); cvars[j].nx += cvars[j].offset; - printLine(tv.name, cx, tv.format); + printLine(tv_.name, cx, tv_.format); newLine(); cy++; continue; } - if (!tv.isEmpty()) { + if (!tv_.isEmpty()) { switch (ccol.alignment) { case Nothing: - cvars[j].offset = (tv.name + ": ").length(); + cvars[j].offset = (tv_.name + ": ").length(); cvars[j].nx += cvars[j].offset; - printValue(tv.name + ": ", tv.format); + printValue(tv_.name + ": ", tv_.format); break; case Left: cvars[j].offset = mx; cvars[j].nx += cvars[j].offset; - printValue(tv.name + ": ", tv.format); + printValue(tv_.name + ": ", tv_.format); break; case Right: cvars[j].offset = mx; cvars[j].nx += cvars[j].offset; - dx = mx - (tv.name + ": ").length(); + dx = mx - (tv_.name + ": ").length(); moveRight(dx); - printValue(tv.name + ": ", tv.format); + printValue(tv_.name + ": ", tv_.format); moveLeft(dx); break; } diff --git a/src/console/piconsole.h b/src/console/piconsole.h index de3df362..bf902f7c 100644 --- a/src/console/piconsole.h +++ b/src/console/piconsole.h @@ -336,6 +336,8 @@ private: struct Variable { Variable() {nx = ny = type = offset = bitFrom = bitCount = size = 0; format = Normal; remote = false; ptr = 0; id = 1;} + Variable(const Variable & src) {remote = src.remote; name = src.name; format = src.format; type = src.type; offset = src.offset; size = src.size; + bitFrom = src.bitFrom; bitCount = src.bitCount; ptr = src.ptr; nx = src.nx; ny = src.ny; rdata = src.rdata; id = src.id;} bool isEmpty() const {return (remote ? false : ptr == 0);} const void * data() {return (remote ? rdata.data() : ptr);} void writeData(PIByteArray & ba) { diff --git a/src/console/pikbdlistener.cpp b/src/console/pikbdlistener.cpp index 70608feb..39470961 100644 --- a/src/console/pikbdlistener.cpp +++ b/src/console/pikbdlistener.cpp @@ -131,7 +131,7 @@ PRIVATE_DEFINITION_START(PIKbdListener) PRIVATE_DEFINITION_END(PIKbdListener) -PIKbdListener::PIKbdListener(KBFunc slot, void * _data, bool startNow): PIThread() { +PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread() { setName("keyboard_listener"); _object = this; #ifdef WINDOWS @@ -142,7 +142,7 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * _data, bool startNow): PIThread #endif is_active = true; ret_func = slot; - data_ = _data; + kbddata_ = _d; PIKbdListener::exiting = exit_enabled = false; if (startNow) start(); } @@ -317,8 +317,8 @@ void PIKbdListener::readKeyboard() { return; } if (ret > 0) { - keyPressed(ke, data_); - if (ret_func != 0) ret_func(ke, data_); + keyPressed(ke, kbddata_); + if (ret_func != 0) ret_func(ke, kbddata_); } } diff --git a/src/console/pikbdlistener.h b/src/console/pikbdlistener.h index 2a7503c2..2647bb1b 100644 --- a/src/console/pikbdlistener.h +++ b/src/console/pikbdlistener.h @@ -97,10 +97,10 @@ public: //! Returns custom data - void * data() {return data_;} + void * data() {return kbddata_;} //! Set custom data to "_data" - void setData(void * _data) {data_ = _data;} + void setData(void * _data) {kbddata_ = _data;} //! Set external function to "slot" void setSlot(KBFunc slot) {ret_func = slot;} @@ -185,7 +185,7 @@ private: KBFunc ret_func; int exit_key; bool exit_enabled, is_active; - void * data_; + void * kbddata_; char rc[8]; KeyEvent ke; static PIKbdListener * _object; diff --git a/src/containers/pideque.h b/src/containers/pideque.h index 6c33a184..c7791d75 100755 --- a/src/containers/pideque.h +++ b/src/containers/pideque.h @@ -419,7 +419,9 @@ private: if (as != pid_rsize) { //printf("(%p) realloc %d -> %d (%p)\n", this, pid_rsize, as, pid_data); PIINTROSPECTION_CONTAINER_ALLOC((as-pid_rsize)*sizeof(T)) - pid_data = (T*)(realloc(pid_data, as*sizeof(T))); + T * p_d = (T*)(realloc(pid_data, as*sizeof(T))); + if (p_d) + pid_data = p_d; pid_rsize = as; //printf("(%p) realloc done (%p)\n", this, pid_data); } diff --git a/src/containers/pivector.h b/src/containers/pivector.h index 437990f8..881cf4fe 100755 --- a/src/containers/pivector.h +++ b/src/containers/pivector.h @@ -356,7 +356,9 @@ private: if (as == piv_rsize) return; //cout << std::hex << " ![("< (new 0x" << (llong)piv_data << ") ok]!" << endl; diff --git a/src/core/pibytearray.h b/src/core/pibytearray.h index d6ec7854..71a083f3 100755 --- a/src/core/pibytearray.h +++ b/src/core/pibytearray.h @@ -55,7 +55,8 @@ public: public: //! Constructs data block RawData(void * data = 0, int size = 0) {d = data; s = size;} - //! Constructs data block + RawData(const RawData & o) {d = o.d; s = o.s;} + //! Constructs data block RawData(const void * data, const int size) {d = const_cast(data); s = size;} RawData & operator =(const RawData & o) {d = o.d; s = o.s; return *this;} private: diff --git a/src/core/picout.cpp b/src/core/picout.cpp index c047a18b..43f24fe9 100644 --- a/src/core/picout.cpp +++ b/src/core/picout.cpp @@ -190,7 +190,7 @@ PICout PICout::operator <<(const PICoutAction v) { #define PINUMERICCOUT if (cnb_ == 10) PICOUTTOTARGET(v) else PICOUTTOTARGET(PIString::fromNumber(v, cnb_)) -PICout PICout::operator <<(const char * v) {if (v == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;} +PICout PICout::operator <<(const char * v) {if (v[0] == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;} PICout PICout::operator <<(const std::string & v) {space(); quote(); PICOUTTOTARGET(v) quote(); return *this;} diff --git a/src/core/pistatemachine.h b/src/core/pistatemachine.h index 7b1bf96c..6a4b2b30 100755 --- a/src/core/pistatemachine.h +++ b/src/core/pistatemachine.h @@ -87,7 +87,7 @@ public: //! %Rule of transition between states of machine struct Rule { //! Constuctor - Rule() {handler = 0;} + Rule() {handler = 0; from = to = Type(); autoTransition = resetAllConditions = false;} //! Constuctor Rule(Type f, Type t, const PIStringList & c = PIStringList(), Handler h = 0, bool at = false, bool rac = false) { from = f; @@ -119,7 +119,7 @@ public: //! %State of machine struct State { //! Constuctor - State() {handler = 0;} + State() {handler = 0; value = Type();} //! Constuctor State(Type v, const PIString & n = "", Handler h = 0) {value = v; name = n; handler = h;} //! %State value diff --git a/src/core/pivariant.cpp b/src/core/pivariant.cpp index 00a99270..8831f398 100755 --- a/src/core/pivariant.cpp +++ b/src/core/pivariant.cpp @@ -54,7 +54,17 @@ PIMap * __PIVariantInfoStorage__::map = 0; PIVariant::PIVariant() { - _type = PIVariant::pivInvalid; + _type = PIVariant::pivInvalid; + _info = 0; +} + + +PIVariant::PIVariant(const PIVariant &v) { + _type = v._type; + _content = v._content; +#ifdef CUSTOM_PIVARIANT + _info = v._info; +#endif } diff --git a/src/core/pivariant.h b/src/core/pivariant.h index fb4eb995..7f90faf4 100755 --- a/src/core/pivariant.h +++ b/src/core/pivariant.h @@ -162,6 +162,8 @@ public: //! Empty constructor, \a type() will be set to \a Invalid PIVariant(); + PIVariant(const PIVariant & v); + //! Constructs variant from string PIVariant(const char * v) {initType(PIString(v));} diff --git a/src/io/piconfig.h b/src/io/piconfig.h index 84f70b80..f913a8b2 100755 --- a/src/io/piconfig.h +++ b/src/io/piconfig.h @@ -110,7 +110,7 @@ public: friend class PIConfig; friend class Branch; public: - Entry() {_parent = 0;} + Entry() {_parent = 0; _line = -1;} //! Returns parent entry, or 0 if there is no parent (root of default value) Entry * parent() const {return _parent;} diff --git a/src/io/pifile.cpp b/src/io/pifile.cpp index db9a90a8..6a792133 100755 --- a/src/io/pifile.cpp +++ b/src/io/pifile.cpp @@ -122,12 +122,14 @@ PIString PIFile::FileInfo::dir() const { PIFile::PIFile(): PIIODevice() { + fd = 0; fdi = -1; setPrecision(5); } PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) { + fd = 0; fdi = -1; setPrecision(5); if (!path.isEmpty()) @@ -136,7 +138,8 @@ PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(p PIFile::PIFile(const PIFile & other) { - fdi = -1; + fd = 0; + fdi = -1; setPrecision(other.prec_); setPath(other.path()); mode_ = other.mode_; diff --git a/src/io/pipacketextractor.h b/src/io/pipacketextractor.h index bf8313a9..2fad7a0b 100755 --- a/src/io/pipacketextractor.h +++ b/src/io/pipacketextractor.h @@ -170,7 +170,6 @@ private: PIByteArray buffer, tmpbuf, src_header, src_footer, trbuf; PacketExtractorCheckFunc ret_func_header, ret_func_footer; SplitMode mode_; - void * data; int buffer_size, dataSize, packetSize_hf, footerInd, packetSize_; double time_; bool header_found; diff --git a/src/io/piusb.cpp b/src/io/piusb.cpp index 0caf8941..9c744aea 100755 --- a/src/io/piusb.cpp +++ b/src/io/piusb.cpp @@ -27,8 +27,6 @@ PIUSB::PIUSB(ushort vid, ushort pid): PIIODevice("", ReadWrite) { void PIUSB::Endpoint::parse() { - direction = Write; - transfer_type = Control; synchronisation_type = NoSynchonisation; usage_type = DataEndpoint; direction = (Direction)((address >> 7) & 1); diff --git a/src/math/pievaluator.cpp b/src/math/pievaluator.cpp index c7ecd28f..91a24622 100755 --- a/src/math/pievaluator.cpp +++ b/src/math/pievaluator.cpp @@ -775,7 +775,6 @@ int PIEvaluator::parse(const PIString & string, int offset) { bcnt = farg = 1; ///qDebug() << "function: " + cfunc.identifier; //for (int k = 0; k < facnt; k++) { - bcnt = 1; carg = ""; k = i + 1; //if (string.size_s() <= k || k < 0) return -666; diff --git a/src/math/pievaluator.h b/src/math/pievaluator.h index c96cd56f..f4af2d70 100755 --- a/src/math/pievaluator.h +++ b/src/math/pievaluator.h @@ -49,7 +49,7 @@ namespace PIEvaluatorTypes { }; struct Instruction { - Instruction() {;} + Instruction() {out = -1; function = -1; operation = oNone;} Instruction(Operation oper, PIVector opers, int out_ind, int func = -1) { operation = oper; operators = opers; out = out_ind; function = func;} Operation operation; @@ -58,7 +58,7 @@ namespace PIEvaluatorTypes { int function; }; struct Element { - Element() {;} + Element() {num = 0; var_num = -1; type = etNumber;} Element(eType new_type, int new_num, int new_var_num = -1) {set(new_type, new_num, new_var_num);} void set(eType new_type, int new_num, int new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;} eType type; diff --git a/src/math/pifixedpoint.h b/src/math/pifixedpoint.h index e811f296..c0dc17ba 100644 --- a/src/math/pifixedpoint.h +++ b/src/math/pifixedpoint.h @@ -41,7 +41,7 @@ public: fp & operator =(const float &v) {val = PIFixedPoint(v).val; return *this;} fp & operator =(const double &v) {val = PIFixedPoint(v).val; return *this;} fp & operator =(const long double &v) {val = PIFixedPoint(v).val; return *this;} - fp & operator -() {fp p = fp(*this); p.val = -val; return p;} + fp operator -() {fp p = fp(*this); p.val = -val; return p;} bool operator ==(const fp & v) const {return val == v.val;} bool operator !=(const fp & v) const {return val != v.val;} diff --git a/src/system/piprocess.cpp b/src/system/piprocess.cpp index 2f24dedd..ab3c1da9 100755 --- a/src/system/piprocess.cpp +++ b/src/system/piprocess.cpp @@ -39,6 +39,7 @@ PIProcess::PIProcess(): PIThread() { is_exec = false; g_in = g_out = g_err = false; t_in = t_out = t_err = false; + tf_in = tf_out = tf_err = 0; env = PIProcess::currentEnvironment(); } @@ -180,7 +181,7 @@ void PIProcess::startProc(bool detached) { is_exec = false; for (int i = 0; i < env.size_s(); ++i) delete e[i]; - delete e; + delete[] e; #ifdef WINDOWS delete a; #else diff --git a/utils/code_model_generator/main.cpp b/utils/code_model_generator/main.cpp index 7b1723b0..caf46094 100755 --- a/utils/code_model_generator/main.cpp +++ b/utils/code_model_generator/main.cpp @@ -331,7 +331,7 @@ int main(int argc, char * argv[]) { piDebug = true; PIStringList pf(parser.parsedFiles()); piForeachC (PIString & f, pf) { - if ((womain && (f != parser.mainFile())) || !womain) + if (!womain || (f != parser.mainFile())) piCout << f; } }