Commit 3f7e7fad authored by Pavel Vainerman's avatar Pavel Vainerman

(step 2): fixes after converity scan (https://scan9.coverity.com)

parent 5c020591
...@@ -466,7 +466,7 @@ namespace uniset ...@@ -466,7 +466,7 @@ namespace uniset
return; return;
// Опрос приоритетной очереди // Опрос приоритетной очереди
for( auto it : pmap ) for( auto&& it : pmap )
{ {
if( it.priority > 0 ) if( it.priority > 0 )
{ {
...@@ -491,7 +491,7 @@ namespace uniset ...@@ -491,7 +491,7 @@ namespace uniset
// опять опросим приоритетные // опять опросим приоритетные
if( !prior && i > maxHalf ) if( !prior && i > maxHalf )
{ {
for( auto& p : pmap ) for( auto&& p : pmap )
{ {
if( p.priority > 1 ) if( p.priority > 1 )
{ {
...@@ -505,7 +505,7 @@ namespace uniset ...@@ -505,7 +505,7 @@ namespace uniset
} }
// Опрос приоритетной очереди // Опрос приоритетной очереди
for( auto& it : pmap ) for( auto&& it : pmap )
{ {
if( it.priority > 2 ) if( it.priority > 2 )
{ {
...@@ -1304,8 +1304,8 @@ namespace uniset ...@@ -1304,8 +1304,8 @@ namespace uniset
{ {
if( !force ) if( !force )
{ {
force = true;
std::lock_guard<std::mutex> l(iopollMutex); std::lock_guard<std::mutex> l(iopollMutex);
force = true;
iopoll(); iopoll();
force = false; force = false;
} }
......
...@@ -80,11 +80,18 @@ MBTCPMaster::~MBTCPMaster() ...@@ -80,11 +80,18 @@ MBTCPMaster::~MBTCPMaster()
{ {
if( pollThread ) if( pollThread )
{ {
try
{
pollThread->stop(); pollThread->stop();
if( pollThread->isRunning() ) if( pollThread->isRunning() )
pollThread->join(); pollThread->join();
} }
catch( Poco::NullPointerException& ex )
{
}
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen ) std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
......
...@@ -422,6 +422,12 @@ void MBTCPMultiMaster::MBSlaveInfo::setUse( bool st ) ...@@ -422,6 +422,12 @@ void MBTCPMultiMaster::MBSlaveInfo::setUse( bool st )
use = st; use = st;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool MBTCPMultiMaster::MBSlaveInfo::isUse()
{
std::lock_guard<std::mutex> l(mutInit);
return use;
}
// -----------------------------------------------------------------------------
bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog ) bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog )
{ {
std::lock_guard<std::mutex> l(mutInit); std::lock_guard<std::mutex> l(mutInit);
......
...@@ -354,6 +354,7 @@ namespace uniset ...@@ -354,6 +354,7 @@ namespace uniset
bool init( std::shared_ptr<DebugStream>& mblog ); bool init( std::shared_ptr<DebugStream>& mblog );
bool check(); bool check();
void setUse( bool st ); void setUse( bool st );
bool isUse();
timeout_t recv_timeout; timeout_t recv_timeout;
timeout_t aftersend_pause; timeout_t aftersend_pause;
......
...@@ -45,7 +45,7 @@ int main(int argc, const char** argv) ...@@ -45,7 +45,7 @@ int main(int argc, const char** argv)
end = std::chrono::system_clock::now(); end = std::chrono::system_clock::now();
int elapsed_seconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); int elapsed_seconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cerr << "elapsed time: " << elapsed_seconds << " ms num=" << num << endl; std::cerr << "elapsed time: " << elapsed_seconds << " ms num=" << num << endl;
std::cerr << "speed: " << ((float)elapsed_seconds / num) << " msg per sec" << endl; std::cerr << "speed: " << ( num > 0 ? ((float)elapsed_seconds / num) : 0 ) << " msg per sec" << endl;
return 0; return 0;
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include "Configuration.h" #include "Configuration.h"
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
#define UI_THROW_EXCEPTIONS uniset::TimeOut,uniset::IOBadParam,uniset::ORepFailed #define UI_THROW_EXCEPTIONS uniset::TimeOut,uniset::IOBadParam,uniset::ORepFailed,uniset::SystemError
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
...@@ -248,7 +248,7 @@ namespace uniset ...@@ -248,7 +248,7 @@ namespace uniset
MaxSize(maxsize), minCallCount(cleancount) {}; MaxSize(maxsize), minCallCount(cleancount) {};
~CacheOfResolve() {}; ~CacheOfResolve() {};
uniset::ObjectPtr resolve( const uniset::ObjectId id, const uniset::ObjectId node ) const throw(uniset::NameNotFound); uniset::ObjectPtr resolve( const uniset::ObjectId id, const uniset::ObjectId node ) const throw(uniset::NameNotFound,uniset::SystemError);
void cache(const uniset::ObjectId id, const uniset::ObjectId node, uniset::ObjectVar& ptr ) const; void cache(const uniset::ObjectId id, const uniset::ObjectId node, uniset::ObjectVar& ptr ) const;
void erase( const uniset::ObjectId id, const uniset::ObjectId node ) const noexcept; void erase( const uniset::ObjectId id, const uniset::ObjectId node ) const noexcept;
......
...@@ -757,7 +757,7 @@ namespace uniset ...@@ -757,7 +757,7 @@ namespace uniset
void ReadInputStatusMessage::init( const ModbusMessage& m ) void ReadInputStatusMessage::init( const ModbusMessage& m )
{ {
assert( m.pduhead.func == fnReadInputStatus ); assert( m.pduhead.func == fnReadInputStatus );
memcpy(this, &m.pduhead, sizeof(m.pduhead) + szData()); memcpy(this, &(m.pduhead), sizeof(m.pduhead) + szData());
// переворачиваем слова // переворачиваем слова
start = SWAPSHORT(start); start = SWAPSHORT(start);
...@@ -961,8 +961,10 @@ namespace uniset ...@@ -961,8 +961,10 @@ namespace uniset
void ReadOutputMessage::init( const ModbusMessage& m ) void ReadOutputMessage::init( const ModbusMessage& m )
{ {
assert( m.pduhead.func == fnReadOutputRegisters ); assert( m.pduhead.func == fnReadOutputRegisters );
func = m.pduhead.func;
addr = m.pduhead.addr;
//memset(this, 0, sizeof(*this)); //memset(this, 0, sizeof(*this));
memcpy(this, &m.pduhead, sizeof(m.pduhead) + szData()); memcpy(&start, &m.data, szData());
// переворачиваем слова // переворачиваем слова
start = SWAPSHORT(start); start = SWAPSHORT(start);
......
...@@ -1265,23 +1265,30 @@ namespace uniset ...@@ -1265,23 +1265,30 @@ namespace uniset
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
uniset::ObjectPtr UInterface::CacheOfResolve::resolve( const uniset::ObjectId id, const uniset::ObjectId node ) const uniset::ObjectPtr UInterface::CacheOfResolve::resolve( const uniset::ObjectId id, const uniset::ObjectId node ) const
throw(uniset::NameNotFound) throw(uniset::NameNotFound,uniset::SystemError)
{
try
{ {
uniset::uniset_rwmutex_rlock l(cmutex); uniset::uniset_rwmutex_rlock l(cmutex);
auto it = mcache.find( uniset::key(id, node) ); auto it = mcache.find( uniset::key(id, node) );
if( it == mcache.end() ) if( it != mcache.end() )
throw uniset::NameNotFound(); {
it->second.ncall++; it->second.ncall++;
// т.к. функция возвращает указатель // т.к. функция возвращает указатель
// и тот кто вызывает отвечает за освобождение памяти // и тот кто вызывает отвечает за освобождение памяти
// то мы делаем _duplicate.... // то мы делаем _duplicate....
if( !CORBA::is_nil(it->second.ptr) ) if( !CORBA::is_nil(it->second.ptr) )
return CORBA::Object::_duplicate(it->second.ptr); return CORBA::Object::_duplicate(it->second.ptr);
}
}
catch( std::exception& ex )
{
uwarn << "UI(CacheOfResolve::resolve): exception: " << ex.what() << endl;
throw uniset::SystemError(ex.what());
}
throw uniset::NameNotFound(); throw uniset::NameNotFound();
} }
...@@ -1305,6 +1312,8 @@ namespace uniset ...@@ -1305,6 +1312,8 @@ namespace uniset
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
bool UInterface::CacheOfResolve::clean() noexcept bool UInterface::CacheOfResolve::clean() noexcept
{ {
try
{
uniset::uniset_rwmutex_wrlock l(cmutex); uniset::uniset_rwmutex_wrlock l(cmutex);
uinfo << "UI: clean cache...." << endl; uinfo << "UI: clean cache...." << endl;
...@@ -1322,6 +1331,11 @@ namespace uniset ...@@ -1322,6 +1331,11 @@ namespace uniset
else else
++it; ++it;
} }
}
catch( std::exception& ex )
{
uwarn << "UI::Chache::clean: exception: " << ex.what() << endl;
}
if( mcache.size() < MaxSize ) if( mcache.size() < MaxSize )
return true; return true;
...@@ -1341,7 +1355,10 @@ namespace uniset ...@@ -1341,7 +1355,10 @@ namespace uniset
if( it != mcache.end() ) if( it != mcache.end() )
mcache.erase(it); mcache.erase(it);
} }
catch(...) {} catch( std::exception& ex )
{
uwarn << "UI::Chache::erase: exception: " << ex.what() << endl;
}
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
......
...@@ -238,11 +238,15 @@ std::ostream& DebugStream::printDateTime(Debug::type t) noexcept ...@@ -238,11 +238,15 @@ std::ostream& DebugStream::printDateTime(Debug::type t) noexcept
<< std::setw(2) << std::setfill('0') << tms.tm_sec; << std::setw(2) << std::setfill('0') << tms.tm_sec;
#endif #endif
std::ios_base::fmtflags old_flags = this->flags();
if( show_usec ) if( show_usec )
(*this) << "." << std::setw(6) << std::setfill('0') << (tv.tv_nsec / 1000); (*this) << "." << std::setw(6) << std::setfill('0') << (tv.tv_nsec / 1000);
else if( show_msec ) else if( show_msec )
(*this) << "." << std::setw(3) << std::setfill('0') << (tv.tv_nsec / 1000000); (*this) << "." << std::setw(3) << std::setfill('0') << (tv.tv_nsec / 1000000);
this->setf(old_flags);
return *this; return *this;
} }
......
...@@ -215,7 +215,14 @@ bool gdb_print_trace() ...@@ -215,7 +215,14 @@ bool gdb_print_trace()
char pid_buf[30]; char pid_buf[30];
sprintf(pid_buf, "%d", getpid()); sprintf(pid_buf, "%d", getpid());
char name_buf[512]; char name_buf[512];
name_buf[readlink("/proc/self/exe", name_buf, 511)] = 0; ssize_t ind = readlink("/proc/self/exe", name_buf, 511);
if( ind < 0 )
{
perror("Can't readlink...");
return false;
}
name_buf[ind] = 0;
TRACELOG << "stack trace: for " << name_buf << " pid=" << pid_buf << endl; TRACELOG << "stack trace: for " << name_buf << " pid=" << pid_buf << endl;
......
...@@ -624,7 +624,7 @@ IOController::USensorInfo::operator=(IOController_i::SensorIOInfo* r) ...@@ -624,7 +624,7 @@ IOController::USensorInfo::operator=(IOController_i::SensorIOInfo* r)
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void* IOController::USensorInfo::getUserData( size_t index ) void* IOController::USensorInfo::getUserData( size_t index )
{ {
if( index > MaxUserData ) if( index >= MaxUserData )
return nullptr; return nullptr;
uniset::uniset_rwmutex_rlock ulock(userdata_lock); uniset::uniset_rwmutex_rlock ulock(userdata_lock);
...@@ -633,7 +633,7 @@ void* IOController::USensorInfo::getUserData( size_t index ) ...@@ -633,7 +633,7 @@ void* IOController::USensorInfo::getUserData( size_t index )
void IOController::USensorInfo::setUserData( size_t index, void* data ) void IOController::USensorInfo::setUserData( size_t index, void* data )
{ {
if( index > MaxUserData ) if( index >= MaxUserData )
return; return;
uniset::uniset_rwmutex_wrlock ulock(userdata_lock); uniset::uniset_rwmutex_wrlock ulock(userdata_lock);
......
...@@ -175,6 +175,8 @@ void IONotifyController::showStatisticsForConsumer( ostringstream& inf, const st ...@@ -175,6 +175,8 @@ void IONotifyController::showStatisticsForConsumer( ostringstream& inf, const st
} }
else else
{ {
std::ios_base::fmtflags old_flags = inf.flags();
inf << std::right; inf << std::right;
auto oind = uniset_conf()->oind; auto oind = uniset_conf()->oind;
...@@ -190,6 +192,8 @@ void IONotifyController::showStatisticsForConsumer( ostringstream& inf, const st ...@@ -190,6 +192,8 @@ void IONotifyController::showStatisticsForConsumer( ostringstream& inf, const st
<< " ]" << " ]"
<< endl; << endl;
} }
inf.setf(old_flags);
} }
inf << "--------------------------------------------" << endl; inf << "--------------------------------------------" << endl;
......
...@@ -139,9 +139,6 @@ namespace uniset ...@@ -139,9 +139,6 @@ namespace uniset
localNodeName(""), localNodeName(""),
fileConfName(xmlfile) fileConfName(xmlfile)
{ {
if( xmlfile.empty() )
setConfFileName();
initConfiguration(argc, argv); initConfiguration(argc, argv);
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
...@@ -158,9 +155,6 @@ namespace uniset ...@@ -158,9 +155,6 @@ namespace uniset
localNodeName(""), localNodeName(""),
fileConfName(fileConf) fileConfName(fileConf)
{ {
if( fileConf.empty() )
setConfFileName();
oind = _oind; oind = _oind;
initConfiguration(argc, argv); initConfiguration(argc, argv);
} }
...@@ -177,9 +171,6 @@ namespace uniset ...@@ -177,9 +171,6 @@ namespace uniset
localNodeName(""), localNodeName(""),
fileConfName(fileConf) fileConfName(fileConf)
{ {
if( fileConf.empty() )
setConfFileName();
shared_ptr<ObjectIndex_Array> _oi = make_shared<ObjectIndex_Array>(omap); shared_ptr<ObjectIndex_Array> _oi = make_shared<ObjectIndex_Array>(omap);
oind = static_pointer_cast<ObjectIndex>(_oi); oind = static_pointer_cast<ObjectIndex>(_oi);
...@@ -188,9 +179,6 @@ namespace uniset ...@@ -188,9 +179,6 @@ namespace uniset
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
void Configuration::initConfiguration( int argc, const char* const* argv ) void Configuration::initConfiguration( int argc, const char* const* argv )
{ {
// PassiveTimer pt(UniSetTimer::WaitUpTime);
ulogsys << "*** configure from file: " << fileConfName << endl;
// т.к. мы не знаем откуда эти argc и argv и может они будут удалены сразу после завершения функции // т.к. мы не знаем откуда эти argc и argv и может они будут удалены сразу после завершения функции
// то надёжнее скопировать себе всё.. // то надёжнее скопировать себе всё..
_argc = argc; _argc = argc;
...@@ -201,6 +189,13 @@ namespace uniset ...@@ -201,6 +189,13 @@ namespace uniset
iorfile = make_shared<IORFile>(); iorfile = make_shared<IORFile>();
// инициализировать надо после argc,argv
if( fileConfName.empty() )
setConfFileName();
// PassiveTimer pt(UniSetTimer::WaitUpTime);
ulogsys << "*** configure from file: " << fileConfName << endl;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
xmlSensorsSec = 0; xmlSensorsSec = 0;
xmlObjectsSec = 0; xmlObjectsSec = 0;
......
...@@ -102,7 +102,15 @@ uniset_rwmutex_wrlock::uniset_rwmutex_wrlock( uniset_rwmutex& _m ): ...@@ -102,7 +102,15 @@ uniset_rwmutex_wrlock::uniset_rwmutex_wrlock( uniset_rwmutex& _m ):
uniset_rwmutex_wrlock::~uniset_rwmutex_wrlock() uniset_rwmutex_wrlock::~uniset_rwmutex_wrlock()
{ {
try
{
m.unlock(); m.unlock();
}
//catch( Poco::SystemException& ex )
catch( std::exception& ex )
{
std::terminate();
}
} }
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
uniset_rwmutex_rlock::uniset_rwmutex_rlock( uniset_rwmutex& _m ): uniset_rwmutex_rlock::uniset_rwmutex_rlock( uniset_rwmutex& _m ):
...@@ -113,6 +121,13 @@ uniset_rwmutex_rlock::uniset_rwmutex_rlock( uniset_rwmutex& _m ): ...@@ -113,6 +121,13 @@ uniset_rwmutex_rlock::uniset_rwmutex_rlock( uniset_rwmutex& _m ):
uniset_rwmutex_rlock::~uniset_rwmutex_rlock() uniset_rwmutex_rlock::~uniset_rwmutex_rlock()
{ {
try
{
m.unlock(); m.unlock();
}
catch( std::exception& ex )
{
std::terminate();
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -306,8 +306,10 @@ void SViewer::updateThresholds( IONotifyController_i::ThresholdsListSeq_var& tls ...@@ -306,8 +306,10 @@ void SViewer::updateThresholds( IONotifyController_i::ThresholdsListSeq_var& tls
void SViewer::printInfo(uniset::ObjectId id, const string& sname, long value, const string& supplier, void SViewer::printInfo(uniset::ObjectId id, const string& sname, long value, const string& supplier,
const string& txtname, const string& iotype) const string& txtname, const string& iotype)
{ {
std::ios_base::fmtflags old_flags = cout.flags();
cout << "(" << setw(5) << id << ")" << " | " << setw(2) << iotype << " | " << setw(60) << sname cout << "(" << setw(5) << id << ")" << " | " << setw(2) << iotype << " | " << setw(60) << sname
<< " | " << setw(5) << value << "\t | " << " | " << setw(5) << value << "\t | "
<< setw(40) << left << supplier << endl; // "\t | " << txtname << endl; << setw(40) << left << supplier << endl; // "\t | " << txtname << endl;
cout.setf(old_flags);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -22,6 +22,7 @@ struct TestClass ...@@ -22,6 +22,7 @@ struct TestClass
{ {
TestClass() TestClass()
{ {
memset(&data,0,sizeof(data));
cerr << "TEST CLASS CREATE.." << endl; cerr << "TEST CLASS CREATE.." << endl;
} }
......
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