Commit f7e16de5 authored by Pavel Vainerman's avatar Pavel Vainerman

Очередная порция исправлений по результатам проверки при помощи Coverity.

parent ab7ab90a
......@@ -136,7 +136,7 @@ int main(int argc, char** argv)
try
{
int optindex = 0;
char opt = 0;
int opt = 0;
while(1)
{
......
......@@ -331,7 +331,10 @@ void DBServer_MySQL::createTables( MySQLInterface* db )
throw Exception();
}
for( it.goChildren(); it; it.goNext() )
if( !it.goChildren() )
return;
for( ; it; it.goNext() )
{
if( it.getName() != "comment" )
{
......
......@@ -221,13 +221,14 @@ IOControl::IOControl(UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
int blink3_msec = conf->getArgPInt("--" + prefix + "-blink3-time", it.getProp("blink3-time"), 100);
ptBlink3.setTiming(blink3_msec);
smReadyTimeout = conf->getArgInt("--" + prefix + "-sm-ready-timeout", it.getProp("ready_timeout"));
int sm_tout = conf->getArgInt("--" + prefix + "-sm-ready-timeout", it.getProp("ready_timeout"));
if( smReadyTimeout == 0 )
if( sm_tout == 0 )
smReadyTimeout = 15000;
else if( smReadyTimeout < 0 )
else if( sm_tout < 0 )
smReadyTimeout = UniSetTimer::WaitUpTime;
else
smReadyTimeout = sm_tout;
string sm_ready_sid = conf->getArgParam("--" + prefix + "-sm-ready-test-sid", it.getProp("sm_ready_test_sid"));
sidTestSMReady = conf->getSensorID(sm_ready_sid);
......@@ -1567,7 +1568,6 @@ void IOControl::buildCardsList()
xmlNode* mynode = 0;
UniXML::iterator it1(nnode);
it1.goChildren();
if( it1.goChildren() )
{
......
......@@ -168,6 +168,13 @@ int main(int argc, char* argv[])
// insn_config(card,subdev,chan,100,range,aref);
int fd = open("/dev/stdin", O_NONBLOCK | O_RDONLY );
if( fd == -1 )
{
cerr << "can't open 'stdin'.. error: " << strerror(errno) << endl;
exit(EXIT_FAILURE);
}
helpPrint();
if( openFileXml.length() > 1 && nodeXml.length() > 1)
......@@ -480,6 +487,7 @@ void openXML()
// --------------------------------------------------------------------------
void dispDiagram()
{
std::ios_base::fmtflags old_flags = cout.flags();
cout.setf( ios::right, ios::adjustfield );
cout << endl << "=================================" << endl;
cout << "| data | calibrated |" << endl;
......@@ -494,6 +502,7 @@ void dispDiagram()
cout << "=================================" << endl;
cout << sortedMass.size() << " " << massDat.size() << endl;
cout.setf(old_flags);
}
// --------------------------------------------------------------------------
......@@ -512,7 +521,7 @@ void sortData(bool rise, bool cal)
temp.sort();
list<int>::iterator itl;
list<int>::iterator ite;
int tt = *(temp.end());
int tt = *(--temp.end());
for(itl = temp.begin(); itl != temp.end(); itl++)
{
......
......@@ -14,12 +14,14 @@ LProcessor::LProcessor( const std::string& name ):
{
auto conf = uniset_conf();
sleepTime = conf->getArgPInt("--sleepTime", 200);
smReadyTimeout = conf->getArgInt("--sm-ready-timeout", "");
int tout = conf->getArgInt("--sm-ready-timeout", "");
if( smReadyTimeout == 0 )
if( tout == 0 )
smReadyTimeout = 60000;
else if( smReadyTimeout < 0 )
else if( tout < 0 )
smReadyTimeout = UniSetTimer::WaitUpTime;
else
smReadyTimeout = tout;
sch = make_shared<SchemaXML>();
}
......
......@@ -268,11 +268,11 @@ MBExchange::~MBExchange()
void MBExchange::waitSMReady()
{
// waiting for SM is ready...
timeout_t ready_timeout = uniset_conf()->getArgInt("--" + prefix + "-sm-ready-timeout", "15000");
if( ready_timeout == 0 )
ready_timeout = 15000;
else if( ready_timeout < 0 )
int tout = uniset_conf()->getArgInt("--" + prefix + "-sm-ready-timeout", "15000");
timeout_t ready_timeout = 15000;
if( ready_timeout > 0 )
ready_timeout = tout;
else if( tout < 0 )
ready_timeout = UniSetTimer::WaitUpTime;
if( !shm->waitSMready(ready_timeout, 50) )
......
......@@ -243,7 +243,7 @@ MBSlave::MBSlave(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const
int heartbeatTime = conf->getArgPInt("--" + prefix + "-heartbeat-time", it.getProp("heartbeatTime"), conf->getHeartBeatTime());
if( heartbeatTime )
if( heartbeatTime > 0 )
ptHeartBeat.setTiming(heartbeatTime);
else
ptHeartBeat.setTiming(UniSetTimer::WaitUpTime);
......@@ -461,11 +461,11 @@ void MBSlave::finalThread()
void MBSlave::waitSMReady()
{
// waiting for SM is ready...
timeout_t ready_timeout = uniset_conf()->getArgInt("--" + prefix + "-sm-ready-timeout", "15000");
if( ready_timeout == 0 )
ready_timeout = 15000;
else if( ready_timeout < 0 )
int tout = uniset_conf()->getArgInt("--" + prefix + "-sm-ready-timeout", "15000");
timeout_t ready_timeout = 15000;
if( ready_timeout > 0 )
ready_timeout = tout;
else if( tout < 0 )
ready_timeout = UniSetTimer::WaitUpTime;
if( !shm->waitSMready(ready_timeout, 50) )
......
......@@ -56,14 +56,14 @@ class MBTCPPersistentSlave:
std::string iaddr;
UniSetTypes::ObjectId respond_s;
UniSetTypes::ObjectId respond_s = { UniSetTypes::DefaultObjectId };
IOController::IOStateList::iterator respond_it;
bool invert;
bool invert = { false };
PassiveTimer ptTimeout;
timeout_t tout;
timeout_t tout = { 2000 };
long askCount;
UniSetTypes::ObjectId askcount_s;
UniSetTypes::ObjectId askcount_s = { UniSetTypes::DefaultObjectId };
IOController::IOStateList::iterator askcount_it;
inline void initIterators( const std::shared_ptr<SMInterface>& shm )
......
......@@ -365,7 +365,7 @@ void RRDServer::timerInfo( const UniSetTypes::TimerMessage* tm )
mycrit << err.str() << endl;
}
delete argv;
delete[] argv;
break;
}
}
......
......@@ -454,11 +454,12 @@ void UNetExchange::startReceivers()
void UNetExchange::waitSMReady()
{
// waiting for SM is ready...
timeout_t ready_timeout = uniset_conf()->getArgInt("--unet-sm-ready-timeout", "15000");
int tout = uniset_conf()->getArgInt("--unet-sm-ready-timeout", "15000");
if( ready_timeout == 0 )
ready_timeout = 15000;
else if( ready_timeout < 0 )
timeout_t ready_timeout = 15000;
if( tout > 0 )
ready_timeout = tout;
else if( tout < 0 )
ready_timeout = UniSetTimer::WaitUpTime;
if( !shm->waitSMready(ready_timeout, 50) )
......
......@@ -160,15 +160,15 @@ class UNetExchange:
UniSetTypes::uniset_rwmutex mutex_start;
PassiveTimer ptHeartBeat;
UniSetTypes::ObjectId sidHeartBeat;
timeout_t maxHeartBeat;
UniSetTypes::ObjectId sidHeartBeat = { UniSetTypes::DefaultObjectId };
timeout_t maxHeartBeat = 10;
IOController::IOStateList::iterator itHeartBeat;
UniSetTypes::ObjectId test_id;
UniSetTypes::ObjectId test_id = { UniSetTypes::DefaultObjectId };
timeout_t steptime; /*!< периодичность вызова step, [мсек] */
timeout_t steptime = { 1000 }; /*!< периодичность вызова step, [мсек] */
std::atomic_bool activated;
timeout_t activateTimeout;
std::atomic_bool activated = { false };
timeout_t activateTimeout = { 20000 }; // msec
struct ReceiverInfo
{
......
......@@ -162,8 +162,8 @@ class UNetReceiver:
private:
UNetReceiver();
int recvpause; /*!< пауза меджду приёмами пакетов, [мсек] */
int updatepause; /*!< переодичность обновления данных в SM, [мсек] */
timeout_t recvpause = { 10 }; /*!< пауза меджду приёмами пакетов, [мсек] */
timeout_t updatepause = { 100 }; /*!< переодичность обновления данных в SM, [мсек] */
std::shared_ptr<ost::UDPReceive> udp;
ost::IPV4Address addr;
......@@ -173,11 +173,11 @@ class UNetReceiver:
UniSetTypes::uniset_rwmutex pollMutex;
PassiveTimer ptRecvTimeout;
PassiveTimer ptPrepare;
timeout_t recvTimeout;
timeout_t prepareTime;
timeout_t lostTimeout;
timeout_t recvTimeout = { 5000 }; // msec
timeout_t prepareTime = { 2000 };
timeout_t lostTimeout = { 200 };
PassiveTimer ptLostTimeout;
unsigned long lostPackets = { 0 }; /*!< счётчик потерянных пакетов */
size_t lostPackets = { 0 }; /*!< счётчик потерянных пакетов */
UniSetTypes::ObjectId sidRespond = { UniSetTypes::DefaultObjectId };
IOController::IOStateList::iterator itRespond;
......@@ -194,18 +194,18 @@ class UNetReceiver:
UniSetUDP::UDPMessage pack; /*!< просто буфер для получения очередного сообщения */
UniSetUDP::UDPPacket r_buf;
UniSetTypes::uniset_rwmutex packMutex; /*!< mutex для работы с очередью */
unsigned long pnum; /*!< текущий номер обработанного сообщения, для проверки непрерывности последовательности пакетов */
size_t pnum = { 0 }; /*!< текущий номер обработанного сообщения, для проверки непрерывности последовательности пакетов */
/*! максимальная разница межд номерами пакетов, при которой считается, что счётчик пакетов
* прошёл через максимум или сбился...
*/
unsigned long maxDifferens = { 20 };
size_t maxDifferens = { 20 };
PacketQueue qtmp; /*!< очередь на время обработки(очистки) основной очереди */
bool waitClean = { false }; /*!< флаг означающий, что ждём очистики очереди до конца */
unsigned long rnum = { 0 }; /*!< текущий номер принятого сообщения, для проверки "переполнения" или "сбоя" счётчика */
size_t rnum = { 0 }; /*!< текущий номер принятого сообщения, для проверки "переполнения" или "сбоя" счётчика */
int maxProcessingCount; /*!< максимальное число обрабатываемых за один раз сообщений */
size_t maxProcessingCount = { 100 }; /*!< максимальное число обрабатываемых за один раз сообщений */
bool lockUpdate = { false }; /*!< флаг блокировки сохранения принятых данных в SM */
UniSetTypes::uniset_rwmutex lockMutex;
......
......@@ -244,7 +244,9 @@ void UNetSender::real_send(UniSetUDP::UDPMessage& mypack)
#endif
if( packetnum > UniSetUDP::MaxPacketNum )
// при переходе через ноль (когда счётчик перевалит через UniSetUDP::MaxPacketNum..
// делаем номер пакета "1"
if( packetnum == 0 )
packetnum = 1;
if( !udp->isPending(ost::Socket::pendingOutput) )
......
......@@ -164,8 +164,8 @@ TEST_CASE("[UNetUDP]: UDPMessage", "[unetudp][udpmessage]")
UniSetUDP::UDPPacket p;
size_t len = u.transport_msg(p);
CHECK( len != 0 );
CHECK( a < UniSetUDP::MaxACount );
CHECK( a < UniSetUDP::MaxDCount );
REQUIRE( a < UniSetUDP::MaxACount );
REQUIRE( a < UniSetUDP::MaxDCount );
UniSetUDP::UDPMessage u2(p);
REQUIRE( u2.a_dat[a].id == 100 );
......
......@@ -56,6 +56,14 @@ static bool split_addr( const string& addr, string& host, ost::tpport_t& port )
// --------------------------------------------------------------------------
int main(int argc, char* argv[])
{
size_t n = UniSetUDP::MaxPacketNum;
cout << "n=" << n << endl;
n++;
cout << "n++=" << n << endl;
return 0;
int optindex = 0;
int opt = 0;
Command cmd = cmdNOP;
......@@ -70,7 +78,7 @@ int main(int argc, char* argv[])
size_t count = 50;
bool lost = false;
bool show = false;
int ncycles = -1;
size_t ncycles = 0;
unsigned int nprof = 0;
while(1)
......@@ -311,11 +319,11 @@ int main(int argc, char* argv[])
mypack.addDData(i, i);
udp->setPeer(host, port);
unsigned long packetnum = 0;
size_t packetnum = 0;
UniSetUDP::UDPPacket s_buf;
int nc = 1;
size_t nc = 1;
if( ncycles > 0 )
nc = ncycles;
......
......@@ -57,12 +57,14 @@ UniExchange::UniExchange(UniSetTypes::ObjectId id, UniSetTypes::ObjectId shmID,
ptUpdate.setTiming(updatetime);
smReadyTimeout = conf->getArgInt("--io-sm-ready-timeout", it.getProp("ready_timeout"));
int sm_tout = conf->getArgInt("--io-sm-ready-timeout", it.getProp("ready_timeout"));
if( smReadyTimeout == 0 )
if( sm_tout == 0 )
smReadyTimeout = 15000;
else if( smReadyTimeout < 0 )
else if( sm_tout < 0 )
smReadyTimeout = UniSetTimer::WaitUpTime;
else
smReadyTimeout = sm_tout;
dinfo << myname << "(init): smReadyTimeout=" << smReadyTimeout << endl;
......
......@@ -296,7 +296,7 @@ namespace MTR
val = raw.u2.val * pow( (long)10, (long)raw.u2.exp );
}
T5( const ModbusRTU::ModbusData* data, int size )
T5( const ModbusRTU::ModbusData* data, int size ):val(0)
{
if( size >= u2size )
{
......
......@@ -264,7 +264,8 @@ class IONotifyController:
si(si), type(t), list( std::move(list) ) {}
UniSetTypes::uniset_rwmutex mut;
IOController_i::SensorInfo si; /*!< аналоговый датчик */
IOController_i::SensorInfo si = { UniSetTypes::DefaultObjectId, UniSetTypes::DefaultObjectId };
std::shared_ptr<USensorInfo> ait;
UniversalIO::IOType type = { UniversalIO::AI };
ThresholdExtList list; /*!< список порогов по данному аналоговому датчику */
......
......@@ -185,8 +185,8 @@ namespace ModbusRTU
struct ErrorRetMessage:
public ModbusHeader
{
ModbusByte ecode;
ModbusCRC crc;
ModbusByte ecode = { erNoError };
ModbusCRC crc = { 0 };
// ------- from slave -------
ErrorRetMessage( ModbusMessage& m );
......
......@@ -74,8 +74,6 @@ long pyUInterface::getValue( long id )throw(UException)
{
throw UException(ex.what());
}
throw UException("(getValue): unknown error");
}
//---------------------------------------------------------------------------
void pyUInterface::setValue( long id, long val )throw(UException)
......
......@@ -994,7 +994,7 @@ mbErrCode ModbusClient::recv_pdu( ModbusByte qfunc, ModbusMessage& rbuf, timeout
{
size_t onum = 0;
while( (rlen+2) < sizeof(rbuf) && onum < mPreRDI.objNum )
while( (rlen+2) < sizeof(rbuf.data) && onum < mPreRDI.objNum )
{
// сперва получаем два байта, для определения длины последующих данных
size_t szDataLen = 2; // object id + len
......
......@@ -1650,7 +1650,7 @@ size_t WriteOutputMessage::szData()
// -------------------------------------------------------------------------
int WriteOutputMessage::getDataLen( ModbusMessage& m )
{
if( m.len < 0 )
if( m.len == 0 )
return 0;
// копируем только часть заголовка возвращаем count
......@@ -1845,7 +1845,7 @@ size_t ForceSingleCoilMessage::szData()
// -------------------------------------------------------------------------
int ForceSingleCoilMessage::getDataLen( ModbusMessage& m )
{
if( m.len < 0 )
if( m.len == 0 )
return 0;
return sizeof(ModbusData); // data;
......@@ -2017,7 +2017,7 @@ size_t WriteSingleOutputMessage::szData()
// -------------------------------------------------------------------------
int WriteSingleOutputMessage::getDataLen( ModbusMessage& m )
{
if( m.len < 0 )
if( m.len == 0 )
return 0;
return sizeof(ModbusData); // data;
......@@ -3148,7 +3148,7 @@ size_t RemoteServiceMessage::szData()
// -------------------------------------------------------------------------
int RemoteServiceMessage::getDataLen( ModbusMessage& m )
{
if( m.len < 0 )
if( m.len == 0 )
return 0;
// RemoteServiceMessage wm(m);
......@@ -3297,7 +3297,7 @@ size_t ReadFileRecordMessage::szData()
// -------------------------------------------------------------------------
int ReadFileRecordMessage::getDataLen( ModbusMessage& m )
{
if( m.len < 0 )
if( m.len == 0 )
return 0;
return (int)(m.data[0]);
......@@ -3409,16 +3409,17 @@ void FileTransferRetMessage::init( ModbusMessage& m )
memcpy(&numfile, &(m.data[1]), sizeof(ModbusData));
memcpy(&numpacks, &(m.data[1 + sizeof(ModbusData)]), sizeof(ModbusData));
memcpy(&packet, &(m.data[1 + 2 * sizeof(ModbusData)]), sizeof(ModbusData));
numfile = SWAPSHORT(numfile);
numpacks = SWAPSHORT(numpacks);
packet = SWAPSHORT(packet);
dlen = m.data[7];
numfile = SWAPSHORT(numfile);
numpacks = SWAPSHORT(numpacks);
packet = SWAPSHORT(packet);
dlen = m.data[7];
memcpy(data, &(m.data[8]), dlen);
memcpy(&crc, &(m.data[8 + dlen]), szCRC);
}
// -----------------------------------------------------------------------
FileTransferRetMessage::FileTransferRetMessage( ModbusAddr _from ):
bcnt(0),
numfile(0),
numpacks(0),
packet(0),
......
......@@ -99,6 +99,7 @@ namespace UniSetTypes
Configuration::Configuration():
oind(NULL),
_argv(nullptr),
NSName("NameService"),
repeatCount(2), repeatTimeout(100),
localDBServer(UniSetTypes::DefaultObjectId),
......
......@@ -119,7 +119,7 @@ TEST_CASE("UniXML::iterator", "[unixml][iterator][basic]" )
CHECK( it.getName() == "UNISETPLC" );
it = uxml.begin();
it.goChildren();
REQUIRE( it.goChildren() == true );
it.goEnd();
CHECK( it.getName() == "EndSection" );
it.goBegin();
......@@ -155,7 +155,8 @@ TEST_CASE("UniXML::iterator::find", "[unixml][iterator-find][basic]" )
// REQUIRE( it.getProp("name") == "Test4" );
UniXML::iterator sIt(it);
sIt.goChildren();
REQUIRE( sIt.goChildren() == true );
CHECK( sIt.find("subnode") );
REQUIRE( sIt.getProp("name") == "Test5" );
......
......@@ -19,10 +19,14 @@ int main( int argc, char* argv[] )
return session.run();
}
catch( UniSetTypes::Exception& ex )
catch( const UniSetTypes::Exception& ex )
{
std::cerr << ex << std::endl;
}
catch( const std::exception& ex )
{
std::cerr << ex.what() << std::endl;
}
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment