Skip to content

Convert global std::string to constexpr const char*#563

Closed
gaul wants to merge 15 commits into
intel:thermald_nextfrom
gaul:error-prone/throwing-static-init
Closed

Convert global std::string to constexpr const char*#563
gaul wants to merge 15 commits into
intel:thermald_nextfrom
gaul:error-prone/throwing-static-init

Conversation

@gaul
Copy link
Copy Markdown
Contributor

@gaul gaul commented May 6, 2026

Found via bugprone-throwing-static-initialization.

gaul and others added 15 commits April 29, 2026 13:23
This avoids unneeded system calls.

Signed-off-by: Andrew Gaul <andrew@gaul.org>
Use O_NOFOLLOW to avoid symbolic links.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
The loop had no termination condition, so when no trip point of the
requested type existed, the unsigned index underflowed past 0 to
UINT_MAX and the loop read trip_points out of bounds indefinitely.
Bound the loop with j >= 0 so it exits cleanly when no match is found.

Signed-off-by: Andrew Gaul <andrew@gaul.org>

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Andrew Gaul <andrew@gaul.org>
When in the config directory the file "thermald-features.xml" is
present, it gives ability to disable some features. Currently
it allows
DbusControl
XMLThermalConfig
DataVaultFromFileSystem
KobjectUeventSupport

When 0 that feature is disabled.

If the file is absent all features are enabled.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Use feature configs to enable/disable a feature.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
thd_sys_fs.cpp:203:4: warning: Value stored to 'ret' is never
read [clang-analyzer-deadcode.DeadStores]
  203 |                         ret = -EIO;

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Use O_NOFOLLOW when opening lock file. Also replace
std::ofstream fout with open with O_NOFOLLOW.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Read one less than size of string via pread and foce NULL
characted at the last character.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
No need for static for pref_str.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Move to TDRUNDIR instead of /tmp.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Although data vault source is BIOS, check for buffer overflows.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Add get_string_obj() which checks for bounds in GDDV.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
When reading from file system use sysfs class, so that all file
operations uses same method.

Signed-off-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Found via bugprone-throwing-static-initialization.

Signed-off-by: Andrew Gaul <andrew@gaul.org>
@gaul gaul force-pushed the error-prone/throwing-static-init branch from cd63cfd to 81c3971 Compare May 6, 2026 00:13
@spandruvada spandruvada requested a review from Copilot May 7, 2026 17:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes non-trivially-initialized global/static std::string storage (flagged by bugprone-throwing-static-initialization) by switching to compile-time string literals (constexpr const char*) for fixed sysfs path lists.

Changes:

  • Replaced std::vector<std::string> blocklist paths with a static constexpr const char*[] in the Intel platform check.
  • Removed the cthd_cdev_backlight static std::string member declaration and replaced the implementation with a file-local static constexpr const char*[] device path list.
  • Replaced a preprocessor macro (#define MAX_BACKLIGHT_DEV) with a static constexpr int.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/thd_platform_intel.cpp Uses a constexpr string-literal array for platform blocklist paths, avoiding static std::string initialization.
src/thd_cdev_backlight.h Removes the static std::string member declaration that required static initialization.
src/thd_cdev_backlight.cpp Defines backlight device paths as a file-local constexpr array and replaces the macro with constexpr.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@spandruvada
Copy link
Copy Markdown
Contributor

Merged, Closed.

@gaul gaul deleted the error-prone/throwing-static-init branch May 13, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants