-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix "ROS_DISTRO" of CI for Jazzy * Add authors * Update README for Jazzy * Modify CI to ensure compatibility with the act tool * Add messages of compiler version message for debug * add ccache setting * Set log level "debug" for CI * comment out env for debug * Replace "ROS_REPO: [ros]" with "ROS_REPO: [main]" for CI of "ROS 2" * Fix undefined behavior by storing `std::string` objects instead of `const char*` pointers Previously, the test code for the 9-axis IMU was storing `const char*` pointers obtained from temporary `std::string` objects into a vector. Since these temporary `std::string` objects are destroyed immediately after the expression, the stored pointers became invalid (dangling pointers), leading to undefined behavior and causing tests to fail. This commit fixes the issue by changing the vector to store *std::string* objects directly instead of `const char*` pointers. By maintaining the `std::string` objects, we ensure that the data remains valid throughout its usage, and any `c_str()` calls on these strings return valid pointers. This change resolves the test failures and prevents potential crashes or incorrect data processing due to invalid memory access. * Update copyright year
- Loading branch information
Showing
5 changed files
with
50 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
<maintainer email="[email protected]">RT Corporation</maintainer> | ||
<author email="[email protected]">RT Corporation</author> | ||
<author email="[email protected]">Yusuke Kato</author> | ||
<author email="[email protected]">Kazushi Kurasawa</author> | ||
|
||
<license>BSD</license> | ||
|
||
|
@@ -29,4 +31,3 @@ | |
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
* License: BSD-3-Clause | ||
* | ||
* Copyright (c) 2015-2023 RT Corporation <[email protected]> | ||
* Copyright (c) 2015-2024 RT Corporation <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -198,29 +198,30 @@ unsigned int create_dummy_ascii_imu_data(unsigned char *buf, bool is_invalid) { | |
unsigned int create_dummy_ascii_imu_data(unsigned char *buf, bool is_invalid, | ||
double *gyro, double *acc, double *mag, double temp) { | ||
rt_usb_9axisimu::Consts consts; | ||
std::vector<const char*> dummy_ascii_imu_data(consts.IMU_ASCII_DATA_SIZE); | ||
std::vector<std::string> dummy_ascii_imu_data(consts.IMU_ASCII_DATA_SIZE); | ||
if (is_invalid) { | ||
dummy_ascii_imu_data[consts.IMU_ASCII_TIMESTAMP] = "0.0"; | ||
} else { | ||
dummy_ascii_imu_data[consts.IMU_ASCII_TIMESTAMP] = "0"; | ||
} | ||
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_X] = double_to_string(gyro[0]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Y] = double_to_string(gyro[1]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Z] = double_to_string(gyro[2]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_X] = double_to_string(acc[0]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Y] = double_to_string(acc[1]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Z] = double_to_string(acc[2]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_X] = double_to_string(mag[0]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Y] = double_to_string(mag[1]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Z] = double_to_string(mag[2]).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_TEMP] = double_to_string(temp).c_str(); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_X] = double_to_string(gyro[0]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Y] = double_to_string(gyro[1]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Z] = double_to_string(gyro[2]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_X] = double_to_string(acc[0]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Y] = double_to_string(acc[1]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Z] = double_to_string(acc[2]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_X] = double_to_string(mag[0]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Y] = double_to_string(mag[1]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Z] = double_to_string(mag[2]); | ||
dummy_ascii_imu_data[consts.IMU_ASCII_TEMP] = double_to_string(temp); | ||
const char split_char = ','; | ||
const char newline_char = '\n'; | ||
buf[0] = (unsigned char)newline_char; | ||
unsigned int char_count = 1; | ||
for(int i = 0; i < consts.IMU_ASCII_DATA_SIZE; i++) { | ||
for(int j = 0; j < (int)strlen(dummy_ascii_imu_data.at(i)); j++) { | ||
buf[char_count] = (unsigned char)dummy_ascii_imu_data.at(i)[j]; | ||
const char* data_str = dummy_ascii_imu_data.at(i).c_str(); | ||
for(int j = 0; j < (int)strlen(data_str); j++) { | ||
buf[char_count] = (unsigned char)data_str[j]; | ||
char_count++; | ||
} | ||
if(i != consts.IMU_ASCII_DATA_SIZE - 1) buf[char_count] = (unsigned char)split_char; | ||
|