* [TE] Fix signed-char tolower UB in PCI BDF lowercasing loops
Follow-up to #2367/#2488 (requested in #2488): the C-style PCI-BDF
lowercasing loops still pass a (possibly signed) char to tolower, which
sign-extends bytes > 0x7F to a negative int — UB, since the argument
must be representable as unsigned char or equal EOF.
Convert the 7 sites (topology.cpp, tent cuda/rocm probes, tent
memory_prober, benchmark te/tent backends) to
static_cast<char>(std::tolower(static_cast<unsigned char>(*ch))),
matching the idiom from #2367, and add/normalize <cctype> includes.
The strings are driver-generated PCI bus ids (ASCII), so this is a
correctness/consistency cleanup; behavior is identical for ASCII.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* [TE] Address review: use a uniform te_lower() helper instead of per-site casts
Per @alogfans's review on #2504/#2488: replace the repeated
static_cast<char>(std::tolower(static_cast<unsigned char>(*ch))) at each
PCI-BDF lowercasing loop with a single inline te_lower() helper added to
common.h. Same well-defined behavior, no more mass typecasts.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* [TE] Move te_lower() to a lightweight char_util.h to fix tent build
The previous commit put te_lower() in common.h, but pulling common.h into
the TENT TUs collides with tent/common/types.h, which defines
LOCAL_SEGMENT_ID as a macro `#define LOCAL_SEGMENT_ID (0ull)` while
common.h declares `const static int LOCAL_SEGMENT_ID = 0;` — the macro
expands inside the declaration and breaks the build (build-flags CI).
Put te_lower() in a new minimal header char_util.h that only pulls in
<cctype>, and include it at all 7 sites instead of common.h. No collision
with the tent macro, still a single uniform helper per @alogfans's review.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* [TE] Name the helper to_lower() to match the std::tolower convention
Rename te_lower() -> to_lower() in char_util.h and the 7 call sites. The
repo has no existing named lowercase helper to reuse, and to_lower reads
naturally alongside std::tolower.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>