Skip to content

Commit

Permalink
Improve timezone handling in 'localtime_r()' using 'allocate_bytes()'
Browse files Browse the repository at this point in the history
Signed-off-by: shamb0 <[email protected]>
  • Loading branch information
shamb0 committed Dec 5, 2024
1 parent 33f6ce9 commit 4745d81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
write!(tm_zone, "{:02}", offset_min).unwrap();
}

// Add null terminator for C string compatibility
// Add null terminator for C string compatibility.
tm_zone.push('\0');

// Deduplicate and allocate the string.
Expand All @@ -208,9 +208,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
MiriMemoryKind::Machine.into(),
Mutability::Not,
)?;

// Write the timezone pointer and offset into the result structure.
this.write_pointer(*tm_zone_ptr, &this.project_field_named(&result, "tm_zone")?)?;
this.write_pointer(tm_zone_ptr, &this.project_field_named(&result, "tm_zone")?)?;
this.write_int_fields_named(&[("tm_gmtoff", tm_gmtoff.into())], &result)?;
}
interp_ok(result.ptr())
Expand Down
10 changes: 5 additions & 5 deletions tests/pass-dep/libc/libc-time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
test_localtime_r_gmt();
test_localtime_r_pst();
test_localtime_r_epoch();
// Architecture-specific tests
// Architecture-specific tests.
#[cfg(target_pointer_width = "32")]
test_localtime_r_future_32b();
#[cfg(target_pointer_width = "64")]
Expand Down Expand Up @@ -53,7 +53,7 @@ fn test_posix_gettimeofday() {
assert_eq!(is_error, -1);
}

// Helper function to create an empty tm struct
// Helper function to create an empty tm struct.
fn create_empty_tm() -> libc::tm {
libc::tm {
tm_sec: 0,
Expand Down Expand Up @@ -121,7 +121,7 @@ fn test_localtime_r_gmt() {
env::remove_var(key);
}

// PST timezone test (testing different timezone handling)
// PST timezone test (testing different timezone handling).
fn test_localtime_r_pst() {
let key = "TZ";
env::set_var(key, "PST8PDT");
Expand Down Expand Up @@ -158,7 +158,7 @@ fn test_localtime_r_pst() {
env::remove_var(key);
}

// Unix epoch test (edge case testing)
// Unix epoch test (edge case testing).
fn test_localtime_r_epoch() {
let key = "TZ";
env::set_var(key, "GMT");
Expand Down Expand Up @@ -195,7 +195,7 @@ fn test_localtime_r_epoch() {
env::remove_var(key);
}

// Future date test (testing large values)
// Future date test (testing large values).
#[cfg(target_pointer_width = "64")]
fn test_localtime_r_future_64b() {
let key = "TZ";
Expand Down

0 comments on commit 4745d81

Please sign in to comment.