diff options
author | lloyd <[email protected]> | 2015-05-15 03:31:56 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-05-15 03:31:56 +0000 |
commit | a4e88fa2610da732ea1125b1ed970baed6d286bb (patch) | |
tree | 10e422f42bcf419bbcec835feb4f41c590286bbe /src/cmd | |
parent | 12eea2e817528e7d1a85e5e80b360eead6e5d206 (diff) |
Fix various bugs found by Coverity scanner.
Uninitialized variables, missing divide by zero checks, missing
virtual destructor, etc. Only thing serious is bug in TLS maximum
fragment decoder; missing breaks in switch statement meant receiver
would treat any negotiated max frament as 4k limit.
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/speed.cpp | 2 | ||||
-rw-r--r-- | src/cmd/timer.cpp | 4 | ||||
-rw-r--r-- | src/cmd/tls_client.cpp | 7 |
3 files changed, 11 insertions, 2 deletions
diff --git a/src/cmd/speed.cpp b/src/cmd/speed.cpp index 185105ee2..516d89d77 100644 --- a/src/cmd/speed.cpp +++ b/src/cmd/speed.cpp @@ -109,12 +109,14 @@ void report_results(const std::string& algo, std::cout << algo; + const std::ios::fmtflags flags = std::cout.flags(); for(auto i = results.rbegin(); i != results.rend(); ++i) { std::cout << " [" << i->second << "] " << std::fixed << std::setprecision(2) << i->first; } std::cout << std::endl; + std::cout.flags(flags); } void time_transform(std::unique_ptr<Transform> tf, diff --git a/src/cmd/timer.cpp b/src/cmd/timer.cpp index 369e3fd04..14e55316b 100644 --- a/src/cmd/timer.cpp +++ b/src/cmd/timer.cpp @@ -47,10 +47,14 @@ std::ostream& operator<<(std::ostream& out, Timer& timer) std::string op_or_ops = (timer.events() == 1) ? "op" : "ops"; + const std::ios::fmtflags flags = out.flags(); + out << std::setprecision(2) << std::fixed << timer.ms_per_event() << " ms/op" << " (" << timer.events() << " " << op_or_ops << " in " << timer.milliseconds() << " ms)"; + out.flags(flags); + return out; } diff --git a/src/cmd/tls_client.cpp b/src/cmd/tls_client.cpp index 44238ec64..d96cc47a9 100644 --- a/src/cmd/tls_client.cpp +++ b/src/cmd/tls_client.cpp @@ -91,7 +91,10 @@ bool handshake_complete(const TLS::Session& session) void dgram_socket_write(int sockfd, const byte buf[], size_t length) { - send(sockfd, buf, length, MSG_NOSIGNAL); + int r = send(sockfd, buf, length, MSG_NOSIGNAL); + + if(r == -1) + throw std::runtime_error("Socket write failed errno=" + std::to_string(errno)); } void stream_socket_write(int sockfd, const byte buf[], size_t length) @@ -108,7 +111,7 @@ void stream_socket_write(int sockfd, const byte buf[], size_t length) if(errno == EINTR) sent = 0; else - throw std::runtime_error("Socket::write: Socket write failed"); + throw std::runtime_error("Socket write failed errno=" + std::to_string(errno)); } offset += sent; |