From 54ab974846428351d48cb17d2aa4be33ea2bc4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 21 Mar 2018 11:34:12 +0200 Subject: [PATCH] Fixed coverity warnings for targets folder. Also fixed one bug while copying sim. --- features/cellular/easy_cellular/CellularConnectionFSM.cpp | 2 +- features/cellular/framework/AT/AT_CellularNetwork.cpp | 4 ++++ .../targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/features/cellular/easy_cellular/CellularConnectionFSM.cpp b/features/cellular/easy_cellular/CellularConnectionFSM.cpp index 0ed414e558..ca7a749985 100644 --- a/features/cellular/easy_cellular/CellularConnectionFSM.cpp +++ b/features/cellular/easy_cellular/CellularConnectionFSM.cpp @@ -136,7 +136,7 @@ bool CellularConnectionFSM::power_on() void CellularConnectionFSM::set_sim_pin(const char * sim_pin) { strncpy(_sim_pin, sim_pin, sizeof(_sim_pin)); - _sim_pin[sizeof(_sim_pin)] = '\0'; + _sim_pin[sizeof(_sim_pin)-1] = '\0'; } bool CellularConnectionFSM::open_sim() diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index ec15f89039..59bddab888 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -310,6 +310,7 @@ nsapi_error_t AT_CellularNetwork::connect() nsapi_error_t AT_CellularNetwork::open_data_channel() { +#if NSAPI_PPP_AVAILABLE tr_info("Open data channel in PPP mode"); _at.cmd_start("AT+CGDATA=\"PPP\","); _at.write_int(_cid); @@ -323,6 +324,9 @@ nsapi_error_t AT_CellularNetwork::open_data_channel() * If blocking: mbed_ppp_init() is a blocking call, it will block until connected, or timeout after 30 seconds*/ return nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularNetwork::ppp_status_cb), NULL, NULL, _ip_stack_type); +#else + return NSAPI_ERROR_OK; +#endif // #if NSAPI_PPP_AVAILABLE } /** diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp index 3af61cb38a..12120bb59c 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp @@ -99,7 +99,7 @@ void QUECTEL_BG96_CellularStack::handle_open_socket_response(int &modem_connect_ } nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *socket) { - int modem_connect_id; + int modem_connect_id = -1; int request_connect_id = socket->id; int remote_port = 0; int err = -1; @@ -246,7 +246,9 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_recvfrom_impl(CellularS recv_len = _at.read_int(); _at.read_string(ip_address, sizeof(ip_address)); port = _at.read_int(); - _at.read_bytes((uint8_t*)buffer, recv_len); + if (recv_len > 0) { + _at.read_bytes((uint8_t*)buffer, recv_len); + } _at.resp_stop(); if (!recv_len || (_at.get_last_error() != NSAPI_ERROR_OK)) {