1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 04:00:34 +00:00

Fix error handling issues detected by Coverity Scan 2020.09

This commit is contained in:
Carles Fernandez 2021-01-25 13:35:47 +01:00
parent 419eff9424
commit 2f627581ef
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
7 changed files with 57 additions and 21 deletions

View File

@ -59,7 +59,10 @@ bool Monitor_Pvt_Udp_Sink::write_monitor_pvt(const Monitor_Pvt* const monitor_pv
try
{
socket.send(boost::asio::buffer(outbound_data));
if (socket.send(boost::asio::buffer(outbound_data)) == 0)
{
return false;
}
}
catch (boost::system::system_error const& e)
{

View File

@ -92,6 +92,8 @@ TwoBitPackedFileSignalSource::TwoBitPackedFileSignalSource(
item_size_ = sizeof(char);
}
reverse_interleaving_ = false;
is_complex_ = true;
if (sample_type_ == "real")
{
is_complex_ = false;
@ -99,7 +101,6 @@ TwoBitPackedFileSignalSource::TwoBitPackedFileSignalSource(
else if (sample_type_ == "iq")
{
is_complex_ = true;
reverse_interleaving_ = false;
}
else if (sample_type_ == "qi")
{

View File

@ -32,6 +32,9 @@ boost::system::error_code rtl_tcp_command(RTL_TCP_COMMAND id, unsigned param, bo
std::memcpy(&data[1], &nparam, sizeof(nparam));
boost::system::error_code ec;
socket.send(boost::asio::buffer(data), 0, ec);
if (socket.send(boost::asio::buffer(data), 0, ec) == 0)
{
// 0 bytes sent
}
return ec;
}

View File

@ -35,8 +35,8 @@ boost::system::error_code Rtl_Tcp_Dongle_Info::read(boost::asio::ip::tcp::socket
boost::system::error_code ec;
unsigned char data[sizeof(char) * 4 + sizeof(uint32_t) * 2];
socket.receive(boost::asio::buffer(data), 0, ec);
if (!ec)
size_t received_bits = socket.receive(boost::asio::buffer(data), 0, ec);
if (!ec && (received_bits > 0))
{
std::memcpy(magic_, data, 4);
@ -46,7 +46,7 @@ boost::system::error_code Rtl_Tcp_Dongle_Info::read(boost::asio::ip::tcp::socket
tuner_type_ = boost::asio::detail::socket_ops::network_to_host_long(type);
uint32_t count;
std ::memcpy(&count, &data[8], 4);
std::memcpy(&count, &data[8], 4);
tuner_gain_count_ = boost::asio::detail::socket_ops::network_to_host_long(count);
}

View File

@ -66,10 +66,16 @@ void Tcp_Communication::send_receive_tcp_packet_galileo_e1(boost::array<float, N
try
{
// Send a TCP packet
tcp_socket_.write_some(boost::asio::buffer(buf));
if (tcp_socket_.write_some(boost::asio::buffer(buf)) == 0)
{
std::cerr << "Tcp_Communication: Error sending TCP packet\n";
}
// Read the received TCP packet
tcp_socket_.read_some(boost::asio::buffer(readbuf));
if (tcp_socket_.read_some(boost::asio::buffer(readbuf)) == 0)
{
std::cerr << "Tcp_Communication: Error reading TCP packet\n";
}
//! Control. The GNSS-SDR program ends if an error in a TCP packet is detected.
if (d_control_id_ != readbuf.data()[0])
@ -100,10 +106,16 @@ void Tcp_Communication::send_receive_tcp_packet_gps_l1_ca(boost::array<float, NU
try
{
// Send a TCP packet
tcp_socket_.write_some(boost::asio::buffer(buf));
if (tcp_socket_.write_some(boost::asio::buffer(buf)) == 0)
{
std::cerr << "Tcp_Communication error sending TCP packet\n";
}
// Read the received TCP packet
tcp_socket_.read_some(boost::asio::buffer(readbuf));
if (tcp_socket_.read_some(boost::asio::buffer(readbuf)) == 0)
{
std::cerr << "Tcp_Communication error: reading 0 bytes from TCP packet\n";
}
//! Control. The GNSS-SDR program ends if an error in a TCP packet is detected.
if (d_control_id_ != readbuf.data()[0])
@ -122,6 +134,10 @@ void Tcp_Communication::send_receive_tcp_packet_gps_l1_ca(boost::array<float, NU
std::cerr << "Exception: " << e.what() << ". Please press Ctrl+C to end the program.\n";
std::cin >> controlc;
}
catch (...)
{
std::cerr << "Exception reading TCP data\n";
}
}

View File

@ -57,10 +57,14 @@ bool Gnss_Synchro_Udp_Sink::write_gnss_synchro(const std::vector<Gnss_Synchro>&
try
{
socket.send(boost::asio::buffer(outbound_data));
if (socket.send(boost::asio::buffer(outbound_data)) == 0)
{
std::cerr << "Gnss_Synchro_Udp_Sink sent 0 bytes\n";
}
}
catch (boost::system::system_error const& e)
{
std::cerr << e.what() << '\n';
return false;
}
}

View File

@ -326,7 +326,7 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
acceptor.accept(socket, not_throw);
if (not_throw)
{
std::cout << "TcpCmdInterface: Error when binding the port in the socket\n";
std::cerr << "TcpCmdInterface: Error when binding the port in the socket\n";
continue;
}
@ -336,7 +336,10 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
{
std::string response;
boost::asio::streambuf b;
boost::asio::read_until(socket, b, '\n', error);
if (boost::asio::read_until(socket, b, '\n', error) == 0)
{
std::cerr << "TcpCmdInterface: Error reading messages: " << error.message() << '\n';
}
std::istream is(&b);
std::string line;
std::getline(is, line);
@ -352,7 +355,10 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
{
error = boost::asio::error::eof;
// send cmd response
socket.write_some(boost::asio::buffer("OK\n"), not_throw);
if (socket.write_some(boost::asio::buffer("OK\n"), not_throw) == 0)
{
std::cerr << "Error: 0 bytes sent in cmd response\n";
}
}
else
{
@ -374,10 +380,13 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
}
// send cmd response
socket.write_some(boost::asio::buffer(response), not_throw);
if (socket.write_some(boost::asio::buffer(response), not_throw) == 0)
{
std::cerr << "Error: 0 bytes sent in cmd response\n";
}
if (not_throw)
{
std::cout << "Error sending(" << not_throw.value() << "): " << not_throw.message() << '\n';
std::cerr << "Error sending(" << not_throw.value() << "): " << not_throw.message() << '\n';
break;
}
}
@ -385,11 +394,11 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
if (error == boost::asio::error::eof)
{
std::cout << "TcpCmdInterface: EOF detected\n";
std::cerr << "TcpCmdInterface: EOF detected\n";
}
else
{
std::cout << "TcpCmdInterface unexpected error: " << error << '\n';
std::cerr << "TcpCmdInterface unexpected error: " << error << '\n';
}
// Close socket
@ -397,16 +406,16 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
}
catch (const boost::exception &e)
{
std::cout << "TcpCmdInterface: Boost exception\n";
std::cerr << "TcpCmdInterface: Boost exception\n";
}
catch (const std::exception &ex)
{
std::cout << "TcpCmdInterface: Exception " << ex.what() << '\n';
std::cerr << "TcpCmdInterface: Exception " << ex.what() << '\n';
}
}
}
catch (const boost::exception &e)
{
std::cout << "TCP Command Interface exception: address already in use\n";
std::cerr << "TCP Command Interface exception: address already in use\n";
}
}