Commit 29709852 authored by Pavel Vainerman's avatar Pavel Vainerman

Coverity scan:

[fixed]: Uninitialized variables (UNINIT) [fixed]: Error handling issues (UNCAUGHT_EXCEPT) [fixed]: Control flow issues (NO_EFFECT) [fixed]: Uninitialized scalar variable (UNINIT)
parent a7d8e78a
......@@ -479,7 +479,7 @@ int main( int argc, char** argv )
cout << "(reply): count=" << ModbusRTU::dat2str(ret.count) << endl;
for( int i = 0; i < ret.count; i++ )
for( size_t i = 0; i < ret.count; i++ )
{
cout << i << ": (" << ModbusRTU::dat2str( reg + i ) << ") = " << (int)(ret.data[i])
<< " ("
......@@ -507,7 +507,7 @@ int main( int argc, char** argv )
cout << "(reply): count=" << ModbusRTU::dat2str(ret.count) << endl;
for( int i = 0; i < ret.count; i++ )
for( size_t i = 0; i < ret.count; i++ )
{
cout << i << ": (" << ModbusRTU::dat2str( reg + i ) << ") = " << (int)(ret.data[i])
<< " ("
......
......@@ -421,7 +421,7 @@ int main( int argc, char** argv )
cout << "(reply): count=" << ModbusRTU::dat2str(ret.count) << endl;
for( int i = 0; i < ret.count; i++ )
for( size_t i = 0; i < ret.count; i++ )
{
cout << i << ": (" << ModbusRTU::dat2str( reg + i ) << ") = " << (int)(ret.data[i])
<< " ("
......@@ -449,7 +449,7 @@ int main( int argc, char** argv )
cout << "(reply): count=" << ModbusRTU::dat2str(ret.count) << endl;
for( int i = 0; i < ret.count; i++ )
for( size_t i = 0; i < ret.count; i++ )
{
cout << i << ": (" << ModbusRTU::dat2str( reg + i ) << ") = " << (int)(ret.data[i])
<< " ("
......
......@@ -79,7 +79,7 @@ int main( int argc, char* argv[], char* envp[] )
while( true )
{
size_t r = read(fileno(stdin), buf, sizeof(buf) - 1);
ssize_t r = read(fileno(stdin), buf, sizeof(buf) - 1);
if( r > 0 )
{
......
......@@ -858,11 +858,13 @@ end_private(false)
resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime));
ptResetMsg.setTiming(resetMsgTime);
smReadyTimeout = conf->getArgInt("--" + argprefix + "sm-ready-timeout","<xsl:call-template name="settings"><xsl:with-param name="varname" select="'smReadyTimeout'"/></xsl:call-template>");
if( smReadyTimeout == 0 )
int sm_tout = conf->getArgInt("--" + argprefix + "sm-ready-timeout","<xsl:call-template name="settings"><xsl:with-param name="varname" select="'smReadyTimeout'"/></xsl:call-template>");
if( sm_tout == 0 )
smReadyTimeout = 60000;
else if( smReadyTimeout &lt; 0 )
else if( sm_tout &lt; 0 )
smReadyTimeout = UniSetTimer::WaitUpTime;
else
smReadyTimeout = sm_tout;
smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"),conf->getProp(cnode,"smTestID"),""));
<xsl:for-each select="//smap/item">
......@@ -1267,11 +1269,13 @@ askPause(uniset_conf()->getPIntProp(cnode,"askPause",2000))
resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime));
ptResetMsg.setTiming(resetMsgTime);
smReadyTimeout = conf->getArgInt("--" + argprefix + "sm-ready-timeout","<xsl:call-template name="settings"><xsl:with-param name="varname" select="'smReadyTimeout'"/></xsl:call-template>");
if( smReadyTimeout == 0 )
int sm_tout = conf->getArgInt("--" + argprefix + "sm-ready-timeout","<xsl:call-template name="settings"><xsl:with-param name="varname" select="'smReadyTimeout'"/></xsl:call-template>");
if( sm_tout == 0 )
smReadyTimeout = 60000;
else if( smReadyTimeout &lt; 0 )
else if( sm_tout &lt; 0 )
smReadyTimeout = UniSetTimer::WaitUpTime;
else
smReadyTimeout = sm_tout;
smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"),conf->getProp(cnode,"smTestID"),""));
......@@ -1454,11 +1458,7 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::strval( UniSetTypes::Object
{
<xsl:if test="normalize-space($onlymsg)=''">
</xsl:if>
// приходится искуственно использовать третий параметр,
// что-бы компилятор выбрал
// правильный(для аналоговых) конструктор у SensorMessage
IOController_i::CalibrateInfo _ci;
SensorMessage _sm( <xsl:value-of select="@name"/>, (long)<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>, _ci);
SensorMessage _sm( <xsl:value-of select="@name"/>, (long)<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/> );
_sm.sensor_type = UniversalIO::AI;
sensorInfo(&amp;_sm);
}
......
......@@ -303,7 +303,10 @@ void DBServer_PostgreSQL::createTables( std::shared_ptr<PostgreSQLInterface>& db
throw Exception();
}
for( it.goChildren(); it; it.goNext() )
if( !it.goChildren() )
return;
for( ; it; it.goNext() )
{
if( it.getName() != "comment" )
{
......
......@@ -203,11 +203,11 @@ PostgreSQLResult::~PostgreSQLResult()
// -----------------------------------------------------------------------------------------
PostgreSQLResult::PostgreSQLResult( const pqxx::result& res )
{
for (result::const_iterator c = res.begin(); c != res.end(); ++c)
for( result::const_iterator c = res.begin(); c != res.end(); ++c )
{
COL col;
for( pqxx::result::tuple::size_type i = 0; i < c.size(); i++ )
for( auto i = 0; i < c.size(); i++ )
col.push_back( c[i].as<string>() );
row.push_back(col);
......
......@@ -306,7 +306,10 @@ void DBServer_SQLite::createTables( SQLiteInterface* db )
throw Exception();
}
for( it.goChildren(); it; it.goNext() )
if( !it.goChildren() )
return;
for( ; it; it.goNext() )
{
if( it.getName() != "comment" )
{
......
......@@ -1569,12 +1569,15 @@ void IOControl::buildCardsList()
UniXML::iterator it1(nnode);
it1.goChildren();
for( ; it1.getCurrent(); it1.goNext() )
if( it1.goChildren() )
{
if( it1.getProp("name") == conf->getLocalNodeName() )
for( ; it1.getCurrent(); it1.goNext() )
{
mynode = it1.getCurrent();
break;
if( it1.getProp("name") == conf->getLocalNodeName() )
{
mynode = it1.getCurrent();
break;
}
}
}
......
......@@ -188,7 +188,13 @@ int main(int argc, char* argv[])
cout << "\r" << "data: " << setw(5) << data << " " << flush;
int temp = read(fd, &buf, sizeof(buf));
ssize_t temp = read(fd, &buf, sizeof(buf));
if( temp == -1 )
{
close(fd);
cerr << "can't read from stdin.. error: " << strerror(errno) << endl;
exit(EXIT_FAILURE);
}
if(temp == 1)
readCalibr(data);
......@@ -319,9 +325,21 @@ void readCalibr(int fixed)
cout << " Enter calibrated value for data=" << fixed << "\n cal = " << flush;
int f = open("/dev/stdin", O_RDONLY );
if( f == -1 )
{
cerr << "read calibrate fail.. error: " << strerror(errno) << endl;
return;
}
memset(rbuf, 0, sizeof(rbuf));
int temp = read(f, &rbuf, sizeof(rbuf));
ssize_t temp = read(f, &rbuf, sizeof(rbuf));
if( temp == -1 )
{
cerr << "read calibrate fail.. error: " << strerror(errno) << endl;
close(f);
return;
}
if (temp > 1)
{
int s;
......@@ -336,6 +354,8 @@ void readCalibr(int fixed)
}
else
cout << " you must input only any digits!" << endl;
close(f);
}
// --------------------------------------------------------------------------
......@@ -533,7 +553,7 @@ void sortData(bool rise, bool cal)
list<int>::iterator ite;
int tt = *(temp.begin());
for(itl = temp.end(); itl != temp.begin(); --itl)
for(itl = --temp.end(); itl != temp.begin(); --itl)
{
if(tt == *itl)continue;
......
......@@ -12,23 +12,23 @@ using namespace UniSetTypes;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("tests");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("tests");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv, "lp-configure.xml");
auto act = UniSetActivator::Instance();
......
......@@ -130,7 +130,11 @@ void RTUStorage::poll( const std::shared_ptr<ModbusRTUMaster>& mb ) throw( Modbu
if( ret.getData(b, bits) )
{
for( unsigned int i = 0; i < 8; i++ )
unio_do[i + 8 * b] = bits[i];
{
int k = i + 8 * b;
if( k<48 )
unio_do[k] = bits[i];
}
}
}
}
......@@ -145,7 +149,11 @@ void RTUStorage::poll( const std::shared_ptr<ModbusRTUMaster>& mb ) throw( Modbu
if( ret.getData(b, bits) )
{
for( unsigned int i = 0; i < 8; i++ )
unio_di[i + 8 * b] = bits[i];
{
int k = i + 8 * b;
if( k<48 )
unio_di[k] = bits[i];
}
}
}
}
......
......@@ -18,24 +18,24 @@ std::shared_ptr<SharedMemory> shm;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("tests_mbtcpmaster");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("tests_mbtcpmaster");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv);
dlog()->logFile("./smtest.log");
......
......@@ -15,24 +15,24 @@ using namespace UniSetExtensions;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_mbtcpmultimaster");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_mbtcpmultimaster");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv);
dlog()->logFile("./smtest.log");
......
......@@ -15,24 +15,24 @@ using namespace UniSetExtensions;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv);
bool apart = findArgParam("--apart", argc, argv) != -1;
......
......@@ -2,7 +2,7 @@ if HAVE_TESTS
noinst_PROGRAMS = tests
tests_SOURCES = NullSM.cc TestObject_SK.cc TestObject.cc tests.cc test_sm.cc
tests_SOURCES = NullSM.cc TestObject_SK.h TestObject_SK.cc TestObject.cc tests.cc test_sm.cc
tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(SIGC_LIBS) $(COMCPP_LIBS)
......
......@@ -18,24 +18,24 @@ std::shared_ptr<TestObject> obj;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("tests");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("tests");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv);
auto shm = SharedMemory::init_smemory(argc, argv);
......
......@@ -28,6 +28,8 @@ namespace UniSetUDP
unsigned long num;
long nodeID;
long procID;
//!\todo может лучше использовать системно-независимый unsigned long, чем size_t?
size_t dcount; /*!< количество булевых величин */
size_t acount; /*!< количество аналоговых величин */
......@@ -35,7 +37,7 @@ namespace UniSetUDP
friend std::ostream& operator<<( std::ostream& os, UDPHeader* p );
} __attribute__((packed));
const unsigned long MaxPacketNum = std::numeric_limits<unsigned long>::max();
const size_t MaxPacketNum = std::numeric_limits<size_t>::max();
struct UDPAData
{
......@@ -100,18 +102,18 @@ namespace UniSetUDP
{
return !((dcount < MaxDCount) && (acount < MaxACount));
}
inline int dsize() const
inline size_t dsize() const
{
return dcount;
}
inline int asize() const
inline size_t asize() const
{
return acount;
}
unsigned short getDataCRC();
// количество байт в пакете с булевыми переменными...
int d_byte() const
size_t d_byte() const
{
return dcount * sizeof(long) + dcount;
}
......
......@@ -158,12 +158,14 @@ TEST_CASE("[UNetUDP]: UDPMessage", "[unetudp][udpmessage]")
{
// создаём сообщение, преобразуем к Package.. потом обратно.. проверяём, что информация не исказилась
UniSetUDP::UDPMessage u;
int a = u.addAData(100, 100);
int d = u.addDData(110, true);
size_t a = u.addAData(100, 100);
size_t d = u.addDData(110, true);
UniSetUDP::UDPPacket p;
size_t len = u.transport_msg(p);
CHECK( len != 0 );
CHECK( a < UniSetUDP::MaxACount );
CHECK( a < UniSetUDP::MaxDCount );
UniSetUDP::UDPMessage u2(p);
REQUIRE( u2.a_dat[a].id == 100 );
......@@ -194,7 +196,7 @@ TEST_CASE("[UNetUDP]: check sender", "[unetudp][sender]")
REQUIRE( pack.asize() == 4 );
REQUIRE( pack.dsize() == 2 );
for( int i = 0; i < pack.asize(); i++ )
for( size_t i = 0; i < pack.asize(); i++ )
{
REQUIRE( pack.a_dat[i].val == i + 1 );
}
......
......@@ -15,24 +15,24 @@ using namespace UniSetExtensions;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
uniset_init(argc, argv);
UNetExchange* unet = UNetExchange::init_unetexchange(argc, argv, getSharedMemoryID());
......
......@@ -15,24 +15,24 @@ using namespace UniSetExtensions;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv);
bool apart = findArgParam("--apart", argc, argv) != -1;
......
......@@ -166,9 +166,6 @@ int main(int argc, char* argv[])
return -1;
}
if( tout < 0 )
tout = TIMEOUT_INF;
ost::Thread::setException(ost::Thread::throwException);
try
......
......@@ -65,6 +65,12 @@ struct IOBase
si.node = UniSetTypes::DefaultObjectId;
cal.minRaw = cal.maxRaw = cal.minCal = cal.maxCal = cal.precision = 0;
ti.invert = false;
ti.hilimit = 0;
ti.lowlimit = 0;
ti.id = UniSetTypes::DefaultObjectId;
ti.state = IONotifyController_i::NormalThreshold;
ti.tv_sec = 0;
ti.tv_usec = 0;
}
bool check_channel_break( long val ); /*!< проверка обрыва провода */
......
......@@ -293,6 +293,7 @@ namespace MTR
T5( long v )
{
raw.lval = v;
val = raw.u2.val * pow( (long)10, (long)raw.u2.exp );
}
T5( const ModbusRTU::ModbusData* data, int size )
......@@ -355,6 +356,7 @@ namespace MTR
T6( long v )
{
raw.lval = v;
val = raw.u2.val * pow( (long)10, (long)raw.u2.exp );
}
T6( const ModbusRTU::ModbusData* data, int size )
......@@ -381,7 +383,7 @@ namespace MTR
return mtT6;
}
// ------------------------------------------
double val;
double val = { 0.0 };
T6mem raw;
};
std::ostream& operator<<(std::ostream& os, T6& t );
......@@ -417,6 +419,7 @@ namespace MTR
T7( const long v )
{
raw.lval = v;
val = raw.u2.val * pow( (long)10, (long) - 4 );
}
T7( const ModbusRTU::ModbusData* data, int size )
......@@ -443,7 +446,7 @@ namespace MTR
return mtT7;
}
// ------------------------------------------
double val;
double val = { 0.0 };
T7mem raw;
};
std::ostream& operator<<(std::ostream& os, T7& t );
......
......@@ -69,6 +69,8 @@ void SingleProcess::set_signals( bool ask )
struct sigaction act, oact;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_RESETHAND;
// добавляем сигналы, которые будут игнорироваться
// при обработке сигнала
sigaddset(&act.sa_mask, SIGINT);
......
......@@ -6,10 +6,10 @@
int main( int argc, char* argv[] )
{
Catch::Session session;
try
{
Catch::Session session;
UniSetTypes::uniset_init(argc, argv);
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
......
......@@ -45,24 +45,24 @@ shared_ptr<SMInterface> smiInstance()
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
try
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
Catch::Session session;
if( argc > 1 && ( strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) )
{
cout << "--confile - Использовать указанный конф. файл. По умолчанию configure.xml" << endl;
SharedMemory::help_print(argc, argv);
cout << endl << endl << "--------------- CATCH HELP --------------" << endl;
session.showHelp("test_with_sm");
return 0;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
try
{
auto conf = uniset_init(argc, argv);
shm = SharedMemory::init_smemory(argc, argv);
......
......@@ -102,10 +102,7 @@ class HourGlass
if( cur > _size )
cur = _size;
_sand -= cur;
if( _sand < 0 )
_sand = 0;
_sand = ( _sand > cur ) ? (_sand - cur) : 0;
t.setTiming(cur);
}
......
......@@ -542,7 +542,7 @@ namespace ModbusRTU
// преобразовании в ModbusMessage.
// Делать что-типа memcpy(buf,this,sizeof(*this)); будет не верно.
// Используйте специальную функцию transport_msg()
int count = { 0 }; /*!< фактическое количество данных в сообщении */
size_t count = { 0 }; /*!< фактическое количество данных в сообщении */
};
std::ostream& operator<<(std::ostream& os, ReadOutputRetMessage& m );
......@@ -633,7 +633,7 @@ namespace ModbusRTU
// преобразовании в ModbusMessage.
// Делать что-типа memcpy(buf,this,sizeof(*this)); будет не верно.
// Используйте специальную функцию transport_msg()
int count = { 0 }; /*!< фактическое количество данных в сообщении */
size_t count = { 0 }; /*!< фактическое количество данных в сообщении */
};
std::ostream& operator<<(std::ostream& os, ReadInputRetMessage& m );
......@@ -1291,7 +1291,7 @@ namespace ModbusRTU
// преобразовании в ModbusMessage.
// Делать что-типа memcpy(buf,this,sizeof(*this)); будет не верно.
// Используйте специальную функцию transport_msg()
int count = { 0 }; /*!< фактическое количество данных в сообщении */
size_t count = { 0 }; /*!< фактическое количество данных в сообщении */
};
std::ostream& operator<<(std::ostream& os, JournalCommandRetMessage& m );
......@@ -1440,7 +1440,7 @@ namespace ModbusRTU
// Это поле не входит в стандарт modbus
// оно вспомогательное и игнорируется при
// преобразовании в ModbusMessage.
unsigned int count = { 0 }; /*!< фактическое количество данных в сообщении */
size_t count = { 0 }; /*!< фактическое количество данных в сообщении */
};
// -----------------------------------------------------------------------
......@@ -1484,7 +1484,7 @@ namespace ModbusRTU
bool checkFormat();
// это поле служебное и не используется в релальном обмене
int count = { 0 }; /*!< фактическое количество данных */
size_t count = { 0 }; /*!< фактическое количество данных */
};
std::ostream& operator<<(std::ostream& os, ReadFileRecordMessage& m );
......
......@@ -28,9 +28,9 @@ void pyUInterface::uniset_init( int argc, char* argv[], const char* xmlfile )thr
{
throw UException(ex.what());
}
catch( ... )
catch( std::exception& ex )
{
throw UException();
throw UException(ex.what());
}
}
//---------------------------------------------------------------------------
......@@ -70,9 +70,9 @@ long pyUInterface::getValue( long id )throw(UException)
{
throw UException(ex.what());
}
catch( ... )
catch( std::exception& ex )
{
throw UException("(getValue): catch...");
throw UException(ex.what());
}
throw UException("(getValue): unknown error");
......@@ -114,9 +114,9 @@ void pyUInterface::setValue( long id, long val )throw(UException)
{
throw UException(ex.what());
}
catch( ... )
catch( std::exception& ex )
{
throw UException("(setValue): catch...");
throw UException(ex.what());
}
}
//---------------------------------------------------------------------------
......@@ -135,7 +135,7 @@ const char* pyUInterface::getName( long id )
auto conf = UniSetTypes::uniset_conf();
if( conf )
return conf->oind->getMapName(id).c_str();
return UniSetTypes::uni_strdup(conf->oind->getMapName(id));
return "";
}
......@@ -145,7 +145,7 @@ const char* pyUInterface::getShortName( long id )
auto conf = UniSetTypes::uniset_conf();
if( conf )
return ORepHelpers::getShortName(conf->oind->getMapName(id)).c_str();
return UniSetTypes::uni_strdup(ORepHelpers::getShortName(conf->oind->getMapName(id)));
return "";
}
......@@ -155,7 +155,7 @@ const char* pyUInterface::getTextName( long id )
auto conf = UniSetTypes::uniset_conf();
if( conf )
return conf->oind->getTextName(id).c_str();
return UniSetTypes::uni_strdup(conf->oind->getTextName(id));
return "";
}
......@@ -165,7 +165,7 @@ const char* pyUInterface::getConfFileName()
auto conf = UniSetTypes::uniset_conf();
if( conf )
return conf->getConfFileName().c_str();
return UniSetTypes::uni_strdup(conf->getConfFileName());
return "";
......
......@@ -51,7 +51,7 @@ const char* UConnector::getConfFileName()
{
// return xmlfile;
if( conf )
return conf->getConfFileName().c_str();
return UniSetTypes::uni_strdup(conf->getConfFileName());
return "";
......@@ -73,12 +73,10 @@ long UConnector::getValue( long id, long node )throw(UException)
{
throw UException(ex.what());
}
catch( ... )
catch( std::exception& ex )
{
throw UException("(getValue): catch...");
throw UException(ex.what());
}
throw UException("(getValue): unknown error");
}
//---------------------------------------------------------------------------
void UConnector::setValue( long id, long val, long node )throw(UException)
......@@ -98,9 +96,9 @@ void UConnector::setValue( long id, long val, long node )throw(UException)
{
throw UException(ex.what());
}
catch( ... )
catch( std::exception& ex )
{
throw UException("(setValue): catch...");
throw UException(ex.what());
}
}
//---------------------------------------------------------------------------
......@@ -123,7 +121,7 @@ long UConnector::getNodeID( const char* name )
const char* UConnector::getName( long id )
{
if( conf )
return conf->oind->getMapName(id).c_str();
return UniSetTypes::uni_strdup(conf->oind->getMapName(id));
return "";
}
......@@ -131,7 +129,7 @@ const char* UConnector::getName( long id )
const char* UConnector::getShortName( long id )
{
if( conf )
return ORepHelpers::getShortName(conf->oind->getMapName(id)).c_str();
return UniSetTypes::uni_strdup(ORepHelpers::getShortName(conf->oind->getMapName(id)));
return "";
}
......@@ -139,7 +137,7 @@ const char* UConnector::getShortName( long id )
const char* UConnector::getTextName( long id )
{
if( conf )
return conf->oind->getTextName(id).c_str();
return UniSetTypes::uni_strdup(conf->oind->getTextName(id));
return "";
}
......
......@@ -997,8 +997,8 @@ mbErrCode ModbusClient::recv_pdu( ModbusByte qfunc, ModbusMessage& rbuf, timeout
while( (rlen+2) < sizeof(rbuf) && onum < mPreRDI.objNum )
{
// сперва получаем два байта, для определения длины последующих данных
int szDataLen = 2; // object id + len
int rlen1 = getNextData((unsigned char*)(&(rbuf.data[rlen])), szDataLen);
size_t szDataLen = 2; // object id + len
size_t rlen1 = getNextData((unsigned char*)(&(rbuf.data[rlen])), szDataLen);
if( rlen1 < szDataLen )
{
......
......@@ -928,7 +928,6 @@ namespace UniSetTypes
// -------------------------------------------------------------------------
string Configuration::getRepSectionName( const string& sec, xmlNode* secnode )
{
secnode = 0;
xmlNode* node = unixml->findNode(unixml->getFirstNode(), sec);
if( node == NULL )
......
......@@ -6,10 +6,10 @@
int main( int argc, char* argv[] )
{
Catch::Session session;
try
{
Catch::Session session;
UniSetTypes::uniset_init(argc, argv);
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
......
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