From 77cda58d73a234e0d2a8f1d8372b5aee7d4d50b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= <beat-kueng@gmx.net> Date: Wed, 6 Apr 2016 09:50:08 +0200 Subject: [PATCH] fix ashtech gps: _satellite_info can be nullptr --- src/drivers/gps/ashtech.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/drivers/gps/ashtech.cpp b/src/drivers/gps/ashtech.cpp index 59a3e9b050..e541064133 100644 --- a/src/drivers/gps/ashtech.cpp +++ b/src/drivers/gps/ashtech.cpp @@ -484,7 +484,7 @@ int ASHTECH::handle_message(int len) return 0; } - if ((this_msg_num == 0) && (bGPS == true)) { + if (this_msg_num == 0 && bGPS && _satellite_info) { memset(_satellite_info->svid, 0, sizeof(_satellite_info->svid)); memset(_satellite_info->used, 0, sizeof(_satellite_info->used)); memset(_satellite_info->snr, 0, sizeof(_satellite_info->snr)); @@ -497,24 +497,28 @@ int ASHTECH::handle_message(int len) if (this_msg_num == all_msg_num) { end = tot_sv_visible - (this_msg_num - 1) * 4; _gps_position->satellites_used = tot_sv_visible; - _satellite_info->count = satellite_info_s::SAT_INFO_MAX_SATELLITES; - _satellite_info->timestamp = hrt_absolute_time(); + if (_satellite_info) { + _satellite_info->count = satellite_info_s::SAT_INFO_MAX_SATELLITES; + _satellite_info->timestamp = hrt_absolute_time(); + } } - for (int y = 0 ; y < end ; y++) { - if (bufptr && *(++bufptr) != ',') { sat[y].svid = strtol(bufptr, &endp, 10); bufptr = endp; } + if (_satellite_info) { + for (int y = 0 ; y < end ; y++) { + if (bufptr && *(++bufptr) != ',') { sat[y].svid = strtol(bufptr, &endp, 10); bufptr = endp; } - if (bufptr && *(++bufptr) != ',') { sat[y].elevation = strtol(bufptr, &endp, 10); bufptr = endp; } + if (bufptr && *(++bufptr) != ',') { sat[y].elevation = strtol(bufptr, &endp, 10); bufptr = endp; } - if (bufptr && *(++bufptr) != ',') { sat[y].azimuth = strtol(bufptr, &endp, 10); bufptr = endp; } + if (bufptr && *(++bufptr) != ',') { sat[y].azimuth = strtol(bufptr, &endp, 10); bufptr = endp; } - if (bufptr && *(++bufptr) != ',') { sat[y].snr = strtol(bufptr, &endp, 10); bufptr = endp; } + if (bufptr && *(++bufptr) != ',') { sat[y].snr = strtol(bufptr, &endp, 10); bufptr = endp; } - _satellite_info->svid[y + (this_msg_num - 1) * 4] = sat[y].svid; - _satellite_info->used[y + (this_msg_num - 1) * 4] = ((sat[y].snr > 0) ? true : false); - _satellite_info->snr[y + (this_msg_num - 1) * 4] = sat[y].snr; - _satellite_info->elevation[y + (this_msg_num - 1) * 4] = sat[y].elevation; - _satellite_info->azimuth[y + (this_msg_num - 1) * 4] = sat[y].azimuth; + _satellite_info->svid[y + (this_msg_num - 1) * 4] = sat[y].svid; + _satellite_info->used[y + (this_msg_num - 1) * 4] = ((sat[y].snr > 0) ? true : false); + _satellite_info->snr[y + (this_msg_num - 1) * 4] = sat[y].snr; + _satellite_info->elevation[y + (this_msg_num - 1) * 4] = sat[y].elevation; + _satellite_info->azimuth[y + (this_msg_num - 1) * 4] = sat[y].azimuth; + } } } -- GitLab