Commit 053f990d authored by Pavel Vainerman's avatar Pavel Vainerman

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

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