mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-31 12:23:23 +08:00
Coverity fixes (#1790)
* Various coverity fixes (High Impact Outstanding) * Removed typo in comment * Removed wrong line of code. * Minor fixes * snprintf finally done right * Added space * Wind direction finally OK
This commit is contained in:
committed by
GitHub
parent
b3042ba955
commit
6b777fcbf3
@@ -78,22 +78,22 @@ void firmware_parse_msg(void)
|
|||||||
case DL_MOVE_WP: {
|
case DL_MOVE_WP: {
|
||||||
if (DL_MOVE_WP_ac_id(dl_buffer) != AC_ID) { break; }
|
if (DL_MOVE_WP_ac_id(dl_buffer) != AC_ID) { break; }
|
||||||
uint8_t wp_id = DL_MOVE_WP_wp_id(dl_buffer);
|
uint8_t wp_id = DL_MOVE_WP_wp_id(dl_buffer);
|
||||||
float a = MOfMM(DL_MOVE_WP_alt(dl_buffer));
|
|
||||||
|
|
||||||
/* Computes from (lat, long) in the referenced UTM zone */
|
/* Computes from (lat, long) in the referenced UTM zone */
|
||||||
struct LlaCoor_f lla;
|
struct LlaCoor_f lla;
|
||||||
lla.lat = RadOfDeg((float)(DL_MOVE_WP_lat(dl_buffer) / 1e7));
|
lla.lat = RadOfDeg((float)(DL_MOVE_WP_lat(dl_buffer) / 1e7));
|
||||||
lla.lon = RadOfDeg((float)(DL_MOVE_WP_lon(dl_buffer) / 1e7));
|
lla.lon = RadOfDeg((float)(DL_MOVE_WP_lon(dl_buffer) / 1e7));
|
||||||
|
lla.alt = MOfMM(DL_MOVE_WP_alt(dl_buffer));
|
||||||
struct UtmCoor_f utm;
|
struct UtmCoor_f utm;
|
||||||
utm.zone = nav_utm_zone0;
|
utm.zone = nav_utm_zone0;
|
||||||
utm_of_lla_f(&utm, &lla);
|
utm_of_lla_f(&utm, &lla);
|
||||||
nav_move_waypoint(wp_id, utm.east, utm.north, a);
|
nav_move_waypoint(wp_id, utm.east, utm.north, utm.alt);
|
||||||
|
|
||||||
/* Waypoint range is limited. Computes the UTM pos back from the relative
|
/* Waypoint range is limited. Computes the UTM pos back from the relative
|
||||||
coordinates */
|
coordinates */
|
||||||
utm.east = waypoints[wp_id].x + nav_utm_east0;
|
utm.east = waypoints[wp_id].x + nav_utm_east0;
|
||||||
utm.north = waypoints[wp_id].y + nav_utm_north0;
|
utm.north = waypoints[wp_id].y + nav_utm_north0;
|
||||||
DOWNLINK_SEND_WP_MOVED(DefaultChannel, DefaultDevice, &wp_id, &utm.east, &utm.north, &a, &nav_utm_zone0);
|
DOWNLINK_SEND_WP_MOVED(DefaultChannel, DefaultDevice, &wp_id, &utm.east, &utm.north, &utm.alt, &nav_utm_zone0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /** NAV */
|
#endif /** NAV */
|
||||||
|
|||||||
@@ -252,7 +252,6 @@ bool nav_compute_final_from_glide(uint8_t wp_af, uint8_t wp_td, float glide)
|
|||||||
|
|
||||||
waypoints[wp_af].x = waypoints[wp_td].x + x_1 * h_0 * glide;
|
waypoints[wp_af].x = waypoints[wp_td].x + x_1 * h_0 * glide;
|
||||||
waypoints[wp_af].y = waypoints[wp_td].y + y_1 * h_0 * glide;
|
waypoints[wp_af].y = waypoints[wp_td].y + y_1 * h_0 * glide;
|
||||||
waypoints[wp_af].a = waypoints[wp_af].a;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ void video_thread_periodic(void)
|
|||||||
video_thread.is_running = ! video_thread.is_running;
|
video_thread.is_running = ! video_thread.is_running;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cv_run_device(NULL,&img);
|
// Calling this function will not work because video_config_t is NULL (?) and img
|
||||||
|
// has no timestamp
|
||||||
|
// Commenting out for now
|
||||||
|
// cv_run_device(NULL,&img);
|
||||||
|
|
||||||
image_free(&img);
|
image_free(&img);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,14 +265,16 @@ void mavlink_common_message_handler(const mavlink_message_t *msg)
|
|||||||
cmd.param_index = settings_idx_from_param_id(cmd.param_id);
|
cmd.param_index = settings_idx_from_param_id(cmd.param_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
mavlink_msg_param_value_send(MAVLINK_COMM_0,
|
// Send message only if the param_index was found (Coverity Scan)
|
||||||
mavlink_param_names[cmd.param_index],
|
if (cmd.param_index > -1) {
|
||||||
settings_get_value(cmd.param_index),
|
mavlink_msg_param_value_send(MAVLINK_COMM_0,
|
||||||
MAV_PARAM_TYPE_REAL32,
|
mavlink_param_names[cmd.param_index],
|
||||||
NB_SETTING,
|
settings_get_value(cmd.param_index),
|
||||||
cmd.param_index);
|
MAV_PARAM_TYPE_REAL32,
|
||||||
MAVLinkSendMessage();
|
NB_SETTING,
|
||||||
|
cmd.param_index);
|
||||||
|
MAVLinkSendMessage();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,22 +160,22 @@ static inline float ground_speed_of_course(float x)
|
|||||||
/* Compute the ground speed for courses 0, 360/NB_ANGLES, ...
|
/* Compute the ground speed for courses 0, 360/NB_ANGLES, ...
|
||||||
(NB_ANGLES-1)360/NB_ANGLES */
|
(NB_ANGLES-1)360/NB_ANGLES */
|
||||||
static void compute_ground_speed(float airspeed,
|
static void compute_ground_speed(float airspeed,
|
||||||
float wind_x,
|
float wind_east,
|
||||||
float wind_y)
|
float wind_north)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
float alpha = 0;
|
float alpha = 0;
|
||||||
float c = wind_x * wind_x + wind_y * wind_y - airspeed * airspeed;
|
float c = wind_north * wind_north + wind_east * wind_east - airspeed * airspeed;
|
||||||
for (i = 0; i < NB_ANGLES; i++, alpha += ANGLE_STEP) {
|
for (i = 0; i < NB_ANGLES; i++, alpha += ANGLE_STEP) {
|
||||||
/* g^2 -2 scal g + c = 0 */
|
/* g^2 -2 scal g + c = 0 */
|
||||||
float scal = wind_x * cos(alpha) + wind_y * sin(alpha);
|
float scal = wind_north * cos(alpha) + wind_east * sin(alpha);
|
||||||
float delta = 4 * (scal * scal - c);
|
float delta = 4 * (scal * scal - c);
|
||||||
ground_speeds[i] = scal + sqrt(delta) / 2.;
|
ground_speeds[i] = scal + sqrt(delta) / 2.;
|
||||||
Bound(ground_speeds[i], NOMINAL_AIRSPEED / 4, 2 * NOMINAL_AIRSPEED);
|
Bound(ground_speeds[i], NOMINAL_AIRSPEED / 4, 2 * NOMINAL_AIRSPEED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjusting a circle around CA, tangent in A, to end at snav_desired_tow */
|
/* Adjusting a circle around CA, tangent in A, to end at snav_desired_tow */
|
||||||
bool snav_on_time(float nominal_radius)
|
bool snav_on_time(float nominal_radius)
|
||||||
{
|
{
|
||||||
nominal_radius = fabs(nominal_radius);
|
nominal_radius = fabs(nominal_radius);
|
||||||
|
|||||||
@@ -289,7 +289,6 @@ bool nav_survey_poly_osam_setup(uint8_t EntryWP, uint8_t Size, float sw, float O
|
|||||||
EntryRadius = -EntryRadius;
|
EntryRadius = -EntryRadius;
|
||||||
dSweep = -sw;
|
dSweep = -sw;
|
||||||
} else {
|
} else {
|
||||||
EntryRadius = EntryRadius;
|
|
||||||
dSweep = sw;
|
dSweep = sw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -588,8 +588,22 @@ int main ( int argc, char** argv)
|
|||||||
/* Obtain sd2log directory */
|
/* Obtain sd2log directory */
|
||||||
char *pprz_home;
|
char *pprz_home;
|
||||||
pprz_home = getenv( "PAPARAZZI_HOME" );
|
pprz_home = getenv( "PAPARAZZI_HOME" );
|
||||||
strcat(sd2log, pprz_home);
|
|
||||||
strcat(sd2log, "/sw/logalizer/sd2log temp.tlm");
|
char *sd2log_home = "/sw/logalizer/sd2log temp.tlm";
|
||||||
|
|
||||||
|
// check if the pprz_home path fits into the sd2log buffer
|
||||||
|
if (strlen(pprz_home) < (sizeof(sd2log) - strlen(sd2log_home))) {
|
||||||
|
strcat(sd2log, pprz_home);
|
||||||
|
strcat(sd2log, sd2log_home);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// pprz_home path too long for the buffer
|
||||||
|
// exit to prevent buffer overflow
|
||||||
|
printf("PPRZ_HOME path too long for the buffer, exiting...\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Get the setting ID with a python script */
|
/* Get the setting ID with a python script */
|
||||||
/* TODO: would be nicer to have a C xml parser */
|
/* TODO: would be nicer to have a C xml parser */
|
||||||
|
|||||||
@@ -506,10 +506,24 @@ static void init_jsbsim(double dt)
|
|||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
string rootdir;
|
string rootdir;
|
||||||
|
string jsbsim_home = "/conf/simulator/jsbsim/";
|
||||||
string jsbsim_ic_name;
|
string jsbsim_ic_name;
|
||||||
|
|
||||||
sprintf(buf, "%s/conf/simulator/jsbsim/", getenv("PAPARAZZI_HOME"));
|
char* pprz_home = getenv("PAPARAZZI_HOME");
|
||||||
rootdir = string(buf);
|
|
||||||
|
int cnt = -1;
|
||||||
|
if (strlen(pprz_home) < sizeof(buf)) {
|
||||||
|
cnt = snprintf(buf, strlen(pprz_home) + 1, "%s", pprz_home);
|
||||||
|
rootdir = string(buf) + jsbsim_home;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check the results
|
||||||
|
if (cnt < 0){
|
||||||
|
// Either pprz_home path too long for the buffer
|
||||||
|
// or writing the string was not successful.
|
||||||
|
cout << "PPRZ_HOME not set correctly, exiting..." << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
/* if jsbsim initial conditions are defined, use them
|
/* if jsbsim initial conditions are defined, use them
|
||||||
* otherwise use flightplan location
|
* otherwise use flightplan location
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ void nps_flightgear_send()
|
|||||||
struct FGNetGUI gui;
|
struct FGNetGUI gui;
|
||||||
|
|
||||||
gui.version = FG_NET_GUI_VERSION;
|
gui.version = FG_NET_GUI_VERSION;
|
||||||
|
gui.padding1 = 0; // initialize the padding variable to zero
|
||||||
|
|
||||||
gui.latitude = fdm.lla_pos.lat;
|
gui.latitude = fdm.lla_pos.lat;
|
||||||
gui.longitude = fdm.lla_pos.lon;
|
gui.longitude = fdm.lla_pos.lon;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ int nps_radio_control_spektrum_init(const char *device)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct termios termios;
|
struct termios termios;
|
||||||
|
termios.c_iflag = 0; // properly initialize variable
|
||||||
/* input modes */
|
/* input modes */
|
||||||
termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
|
termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
|
||||||
| ICRNL | IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
|
| ICRNL | IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
|
||||||
|
|||||||
Reference in New Issue
Block a user