From 49f9394ef1fcc49d15795ab4caf75bda0b7c00cb Mon Sep 17 00:00:00 2001 From: Alex van de Sandt Date: Sun, 28 Dec 2025 14:54:26 -0600 Subject: [PATCH] Clarify string encoding --- src/telemetry/var.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/telemetry/var.rs b/src/telemetry/var.rs index e5530f4..ce12483 100644 --- a/src/telemetry/var.rs +++ b/src/telemetry/var.rs @@ -1,4 +1,4 @@ -use std::ffi::{CStr, c_char}; +use std::ffi::c_char; use indexmap::IndexMap; use num_enum::TryFromPrimitive; @@ -76,11 +76,13 @@ impl VarHeader { } } -// TODO: There may be some weird encoding on these strings fn string_from_c_chars(buf: &[c_char]) -> String { assert!(buf.contains(&0)); - let cstr = unsafe { CStr::from_ptr(buf.as_ptr()) }; - cstr.to_string_lossy().into_owned() + // Strings in iRacing are all ISO-8859-1, which is effectively a subset of UTF-8. Therefore, it + // is safe to interpret a string buffer as unsiged bytes and cast them to UTF-8 codepoints. + // + // https://forums.iracing.com/discussion/comment/703469/#Comment_703469 + buf.iter().map(|c| *c as u8 as char).collect() } #[cfg(test)] -- 2.51.2