Skip to content

Commit 1685a2e

Browse files
committed
Fix usage of starts_with()
starts_with() returns true, if the string starts with the argument string. This matches with C++ 20 expectation. But this broke existing usage. The existing usage should fail if path doesn't starts with "/sys". So the correct replacement of old code should be !starts_with(). Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
1 parent 52d4ebd commit 1685a2e

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/thd_cdev_gen_sysfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
int cthd_gen_sysfs_cdev::update() {
2929
if (cdev_sysfs.exists()) {
3030
std::string base_path = cdev_sysfs.get_base_path();
31-
if (starts_with(base_path, "/sys")) {
31+
if (!starts_with(base_path, "/sys")) {
3232
thd_log_debug( "cthd_gen_sysfs_cdev::update: Invalid sysfs path or allowed path %s\n",
3333
base_path.c_str());
3434
return THD_ERROR;

src/thd_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ int cthd_engine::user_add_sensor(std::string name, std::string path) {
10121012
if (path.empty())
10131013
thd_engine_mutex.unlock();
10141014

1015-
if (starts_with(path, "/sys/")) {
1015+
if (!starts_with(path, "/sys/")) {
10161016
thd_log_debug("Invalid path %s\n", path.c_str());
10171017
return THD_ERROR;
10181018
}

src/thd_engine_default.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int cthd_engine_default::read_thermal_sensors() {
208208
}
209209
sensor_new = std::move(sensor_virt);
210210
} else {
211-
if (starts_with(sensor_config->path, "/sys/")) {
211+
if (!starts_with(sensor_config->path, "/sys/")) {
212212
thd_log_debug( "Invalid sysfs path or allowed path %s\n",
213213
sensor_config->path.c_str());
214214
continue;

src/thd_sensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class cthd_sensor {
7070
int set_threshold(int index, int temp);
7171
;
7272
void update_path(std::string str) {
73-
if (starts_with(str, "/sys/")) {
73+
if (!starts_with(str, "/sys/")) {
7474
thd_log_debug("Invalid path %s\n", str.c_str());
7575
return;
7676
}

0 commit comments

Comments
 (0)