From d1cf852c98cf3d0d83a7cc946d143ecd460ec12b Mon Sep 17 00:00:00 2001 From: Florian Uhlig Date: Thu, 23 Feb 2017 18:44:04 +0100 Subject: [PATCH] Fox Coverity issues Fix CID 131712. In case parameter string does not fit in variable return a failure. Fix CID 162913. Initialize missing data member. Fix CID 58901. Fix CID 149137. Fix CID 149143. Fix CIDs 149156, 149150, 149147, 149145, 149144, 149137. Don't use command line parameter argv directly. --- fairmq/test/pub-sub/runTestPub.cxx | 13 +++++++++---- fairmq/test/pub-sub/runTestSub.cxx | 13 +++++++++---- fairmq/test/push-pull/runTestPull.cxx | 13 +++++++++---- fairmq/test/push-pull/runTestPush.cxx | 16 +++++++++++++--- fairmq/test/req-rep/runTestRep.cxx | 14 ++++++++++---- fairmq/test/req-rep/runTestReq.cxx | 13 +++++++++---- fairmq/test/runTransferTimeoutTest.cxx | 14 ++++++++++---- 7 files changed, 69 insertions(+), 27 deletions(-) diff --git a/fairmq/test/pub-sub/runTestPub.cxx b/fairmq/test/pub-sub/runTestPub.cxx index e841267f..083f5334 100644 --- a/fairmq/test/pub-sub/runTestPub.cxx +++ b/fairmq/test/pub-sub/runTestPub.cxx @@ -26,20 +26,25 @@ int main(int argc, char** argv) testPub.CatchSignals(); std::string transport; - if (argc != 2) + if ( (argc != 2) || (argv[1] == NULL) ) { LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + testPub.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; testPub.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; } diff --git a/fairmq/test/pub-sub/runTestSub.cxx b/fairmq/test/pub-sub/runTestSub.cxx index d79fd3f6..716f066f 100644 --- a/fairmq/test/pub-sub/runTestSub.cxx +++ b/fairmq/test/pub-sub/runTestSub.cxx @@ -28,20 +28,25 @@ int main(int argc, char** argv) testSub.CatchSignals(); std::string transport; - if (argc != 2) + if ( (argc != 2) || (argv[1] == NULL) ) { LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + testSub.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; testSub.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; } diff --git a/fairmq/test/push-pull/runTestPull.cxx b/fairmq/test/push-pull/runTestPull.cxx index 34377eb6..af9ccc6e 100644 --- a/fairmq/test/push-pull/runTestPull.cxx +++ b/fairmq/test/push-pull/runTestPull.cxx @@ -26,20 +26,25 @@ int main(int argc, char** argv) testPull.CatchSignals(); std::string transport; - if (argc != 2) + if ( (argc != 2) || (argv[1] == NULL) ) { LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + testPull.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; testPull.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; } diff --git a/fairmq/test/push-pull/runTestPush.cxx b/fairmq/test/push-pull/runTestPush.cxx index 8c4ecef8..e14ce5db 100644 --- a/fairmq/test/push-pull/runTestPush.cxx +++ b/fairmq/test/push-pull/runTestPush.cxx @@ -32,15 +32,25 @@ int main(int argc, char** argv) LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + if (argv[1] == NULL) { + LOG(ERROR) << "Transport for the test not specified!"; + return 1; + } + + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + testPush.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; testPush.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; } diff --git a/fairmq/test/req-rep/runTestRep.cxx b/fairmq/test/req-rep/runTestRep.cxx index 77fa8991..58d7fa4d 100644 --- a/fairmq/test/req-rep/runTestRep.cxx +++ b/fairmq/test/req-rep/runTestRep.cxx @@ -27,20 +27,26 @@ int main(int argc, char** argv) testRep.CatchSignals(); std::string transport; - if (argc != 2) + if ( (argc != 2) || (argv[1] == NULL) ) { LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + testRep.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; testRep.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; } diff --git a/fairmq/test/req-rep/runTestReq.cxx b/fairmq/test/req-rep/runTestReq.cxx index 925a6bfb..da233737 100644 --- a/fairmq/test/req-rep/runTestReq.cxx +++ b/fairmq/test/req-rep/runTestReq.cxx @@ -28,20 +28,25 @@ int main(int argc, char** argv) testReq.CatchSignals(); std::string transport; - if (argc != 2) + if ( (argc != 2) || (argv[1] == NULL) ) { LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + testReq.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; testReq.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; } diff --git a/fairmq/test/runTransferTimeoutTest.cxx b/fairmq/test/runTransferTimeoutTest.cxx index 21e3f4d5..3202e199 100644 --- a/fairmq/test/runTransferTimeoutTest.cxx +++ b/fairmq/test/runTransferTimeoutTest.cxx @@ -66,20 +66,26 @@ int main(int argc, char** argv) timeoutTester.CatchSignals(); std::string transport; - if (argc != 2) + if ( (argc != 2) || (argv[1] == NULL) ) { LOG(ERROR) << "Transport for the test not specified!"; return 1; } - transport = argv[1]; - if (transport == "zeromq" || transport == "nanomsg") + + if ( strncmp(argv[1],"zeromq",6) == 0 ) { + transport = "zeromq"; + timeoutTester.SetTransport(transport); + } + else if ( strncmp(argv[1],"nanomsg",7) == 0 ) + { + transport = "nanomsg"; timeoutTester.SetTransport(transport); } else { - LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << transport; + LOG(ERROR) << "Incorrect transport requested! Expected 'zeromq' or 'nanomsg', found: " << argv[1]; return 1; }