Fix coverity defects 95/173695/2 accepted/tizen/unified/20180405.064317 submit/tizen/20180404.020934 submit/tizen/20180404.064013
authorsangwan.kwon <sangwan.kwon@samsung.com>
Fri, 23 Mar 2018 07:01:48 +0000 (16:01 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Wed, 28 Mar 2018 04:47:56 +0000 (13:47 +0900)
- Error handling issues
- Control flow issues

Change-Id: I1de11998b681834f179a86b93e8f8638a02d6d95
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
src/file-system.cpp
tests/test-certificate.cpp
tests/test-curl.cpp

index 2171638714483152e09a14a1f3a8868d5e14ce02..55783e0ba6586ffbfb8c6e3e33329379018cabac 100644 (file)
@@ -48,13 +48,17 @@ std::string File::read(const std::string &path)
        if (std::ferror(fp.get()))
                throw std::logic_error("Failed to set the position as end [" + path + "].");
 
-       unsigned int fsize = std::ftell(fp.get());
+       long fsize = std::ftell(fp.get());
+       if (fsize == -1L)
+               throw std::logic_error("Failed to get the position [" + path + "].");
+
        std::fseek(fp.get(), 0L, SEEK_SET);
        if (std::ferror(fp.get()))
                throw std::logic_error("Failed to set the position as beginning [" + path + "].");
 
        std::string buff(fsize, 0);
-       if (fsize != std::fread(static_cast<void*>(&buff[0]), 1, fsize, fp.get()))
+       size_t rsize = std::fread(static_cast<void*>(&buff[0]), 1, fsize, fp.get());
+       if (rsize != static_cast<size_t>(fsize))
                throw std::logic_error("Failed to read [" + path + "]");
 
        return buff;
index 6313163b2cee46ede8aa280d0494232b6dc6bf52..738960c057915d36d6d057ac34de3de98c9391c8 100644 (file)
@@ -36,8 +36,10 @@ TESTCASE(GET_SUBJECT_NAME_HASH)
                TEST_EXPECT(true, hash.compare(TEST_PEM_HASH) == 0);
        } catch (const std::exception &e) {
                std::cout << "std::exception occured." << e.what() << std::endl;
+               TEST_EXPECT(true, false);
        } catch (...) {
                std::cout << "Unknown exception occured." << std::endl;
+               TEST_EXPECT(true, false);
        }
 }
 
@@ -49,7 +51,9 @@ TESTCASE(GET_CERTIFICATE_DATA)
                TEST_EXPECT(true, data.compare(TEST_PEM_DATA) == 0);
        } catch (const std::exception &e) {
                std::cout << "std::exception occured." << e.what() << std::endl;
+               TEST_EXPECT(true, false);
        } catch (...) {
                std::cout << "Unknown exception occured." << std::endl;
+               TEST_EXPECT(true, false);
        }
 }
index 338b9b5bc20dcb5dd4ac98c6e12412a7b7ad144b..09d183e343a9ac9237224c3fc22cef8b55e2d340 100644 (file)
@@ -35,9 +35,6 @@ TESTCASE(CONNECT_SSL)
 {
        int ret = test::util::connectSSL("https://google.com");
        TEST_EXPECT(true, ret == 0);
-
-       if (ret != 0)
-               std::cout << "Check wifi connection.." << std::endl;
 }
 
 TESTCASE(TRUST_ANCHOR_LAUNCH)