Skip to content

Commit 5d2bd94

Browse files
committed
fix(wrt-platform): resolve lifetime issues in random.rs error handling
Fix temporary value lifetime errors in platform random implementation: - Store formatted error messages in variables before passing references - Applies to linux_random(), qnx_random(), and windows_random() functions This resolves compilation errors that were preventing CI from building beyond the initial stages. Related to #99
1 parent 14b3c50 commit 5d2bd94

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

wrt-platform/src/random.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ impl PlatformRandom {
8282

8383
let mut urandom = File::open("/dev/urandom").map_err(|_| Error::runtime_execution_error("Failed to open /dev/urandom"))?;
8484

85-
urandom.read_exact(buffer).map_err(|e| Error::new(
86-
ErrorCategory::Resource,
87-
codes::SYSTEM_IO_ERROR_CODE,
88-
&format!("Failed to read from /dev/urandom: {}", e),
89-
))?;
85+
urandom.read_exact(buffer).map_err(|e| {
86+
let error_msg = format!("Failed to read from /dev/urandom: {}", e);
87+
Error::new(
88+
ErrorCategory::Resource,
89+
codes::SYSTEM_IO_ERROR_CODE,
90+
&error_msg,
91+
)
92+
})?;
9093

9194
Ok(())
9295
}
@@ -149,7 +152,8 @@ impl PlatformRandom {
149152
};
150153

151154
if result != STATUS_SUCCESS {
152-
return Err(Error::runtime_execution_error(&format!("ProcessPrng failed with status: {}", result)));
155+
let error_msg = format!("ProcessPrng failed with status: {}", result);
156+
return Err(Error::runtime_execution_error(&error_msg));
153157
}
154158

155159
Ok(())
@@ -164,11 +168,14 @@ impl PlatformRandom {
164168
// QNX recommends /dev/random for cryptographic purposes
165169
let mut random = File::open("/dev/random").map_err(|_| Error::runtime_execution_error("Failed to open /dev/random"))?;
166170

167-
random.read_exact(buffer).map_err(|e| Error::new(
168-
ErrorCategory::Resource,
169-
codes::SYSTEM_IO_ERROR_CODE,
170-
&format!("Failed to read from /dev/random: {}", e),
171-
))?;
171+
random.read_exact(buffer).map_err(|e| {
172+
let error_msg = format!("Failed to read from /dev/random: {}", e);
173+
Error::new(
174+
ErrorCategory::Resource,
175+
codes::SYSTEM_IO_ERROR_CODE,
176+
&error_msg,
177+
)
178+
})?;
172179

173180
Ok(())
174181
}

0 commit comments

Comments
 (0)