diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2015-03-15 14:33:57 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2015-03-15 14:33:57 +0100 |
commit | 2bddaa9573f0160ad944e1610c87ad48182511d6 (patch) | |
tree | f0cf5c198dea7d677204ad65e99f725ffa864a46 /src/modules/commander | |
parent | 49b3906b7827a7f2b5b4e947d080db7496d044da (diff) | |
download | px4-firmware-2bddaa9573f0160ad944e1610c87ad48182511d6.tar.gz px4-firmware-2bddaa9573f0160ad944e1610c87ad48182511d6.tar.bz2 px4-firmware-2bddaa9573f0160ad944e1610c87ad48182511d6.zip |
commander: Mag calibration: Use c++ syntax for array initialization
Diffstat (limited to 'src/modules/commander')
-rw-r--r-- | src/modules/commander/mag_calibration.cpp | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/modules/commander/mag_calibration.cpp b/src/modules/commander/mag_calibration.cpp index e0786db79..a0aadab39 100644 --- a/src/modules/commander/mag_calibration.cpp +++ b/src/modules/commander/mag_calibration.cpp @@ -164,9 +164,9 @@ int calibrate_instance(int mavlink_fd, unsigned s, unsigned device_id) const unsigned int calibration_maxcount = 240; unsigned int calibration_counter; - float *x = NULL; - float *y = NULL; - float *z = NULL; + float *x = new float[calibration_maxcount]; + float *y = new float[calibration_maxcount]; + float *z = new float[calibration_maxcount]; char str[30]; int res = OK; @@ -174,24 +174,20 @@ int calibrate_instance(int mavlink_fd, unsigned s, unsigned device_id) /* allocate memory */ mavlink_and_console_log_info(mavlink_fd, CAL_PROGRESS_MSG, sensor_name, 20); - x = reinterpret_cast<float *>(malloc(sizeof(float) * calibration_maxcount)); - y = reinterpret_cast<float *>(malloc(sizeof(float) * calibration_maxcount)); - z = reinterpret_cast<float *>(malloc(sizeof(float) * calibration_maxcount)); - - if (x == NULL || y == NULL || z == NULL) { + if (x == nullptr || y == nullptr || z == nullptr) { mavlink_and_console_log_critical(mavlink_fd, "ERROR: out of memory"); /* clean up */ - if (x != NULL) { - free(x); + if (x != nullptr) { + delete x; } - if (y != NULL) { - free(y); + if (y != nullptr) { + delete y; } - if (z != NULL) { - free(z); + if (z != nullptr) { + delete z; } res = ERROR; @@ -274,16 +270,16 @@ int calibrate_instance(int mavlink_fd, unsigned s, unsigned device_id) } } - if (x != NULL) { - free(x); + if (x != nullptr) { + delete x; } - if (y != NULL) { - free(y); + if (y != nullptr) { + delete y; } - if (z != NULL) { - free(z); + if (z != nullptr) { + delete z; } if (res == OK) { |