Skip to content

Commit 08dbc86

Browse files
plm(pr2): fourth review-fix pass (MGudgin comments)
1) src/host/plm/src/main.rs: convert stored blob back to CRLF to match the file's line-ending convention in origin/main; earlier edits inadvertently rewrote it as LF, making the PR diff show a whole-file rewrite. 2) event_parser::render_event_xml: replace unsafe { buf.set_len(0) } with buf.clear() — for Vec<u16> there is nothing to drop and the safe API expresses intent more clearly. 4) event_parser::render_event_xml: fix growth calculation on the ERROR_INSUFFICIENT_BUFFER retry. Vec::reserve(additional) guarantees capacity >= len + additional, and len is 0 here (buf was cleared), so passing (needed_u16 - buf.capacity()) under-reserved when needed_u16 was less than 2*capacity and still under-reserved otherwise. Pass needed_u16 directly. Reverted (was pr2 commit): --with-bfs build.bat additions; the AppContainer Tier 2 BFS build flag will be re-introduced separately per reviewer request. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fc9583d commit 08dbc86

2 files changed

Lines changed: 501 additions & 500 deletions

File tree

src/host/plm/src/event_parser.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn render_event_xml(event: EVT_HANDLE, buf: &mut Vec<u16>) -> Result<String> {
152152
// to the returned u16 count on the SUCCESS path so callers reusing
153153
// `render_buf` across events never observe uninitialized u16s.
154154
//
155-
// `set_len(0)` runs BEFORE the reserve so that `Vec::reserve` —
155+
// `clear()` runs BEFORE the reserve so that `Vec::reserve` —
156156
// which guarantees `capacity ≥ len + additional`, not
157157
// `capacity ≥ additional` — actually reaches the
158158
// `INITIAL_GUESS_U16` target on the first call where `len` had
@@ -165,9 +165,7 @@ fn render_event_xml(event: EVT_HANDLE, buf: &mut Vec<u16>) -> Result<String> {
165165
// BYTE counts, so multiply/divide by `size_of::<u16>()` at the
166166
// Win32 boundary.
167167
const INITIAL_GUESS_U16: usize = 4 * 1024;
168-
unsafe {
169-
buf.set_len(0);
170-
}
168+
buf.clear();
171169
if buf.capacity() < INITIAL_GUESS_U16 {
172170
buf.reserve(INITIAL_GUESS_U16);
173171
}
@@ -203,7 +201,10 @@ fn render_event_xml(event: EVT_HANDLE, buf: &mut Vec<u16>) -> Result<String> {
203201
}
204202
let needed_u16 = (needed as usize).div_ceil(std::mem::size_of::<u16>());
205203
if buf.capacity() < needed_u16 {
206-
buf.reserve(needed_u16 - buf.capacity());
204+
// `Vec::reserve(additional)` measures from `len`, not
205+
// `capacity` — since `buf` is empty (cleared above),
206+
// `additional == needed_u16` gets us `capacity ≥ needed_u16`.
207+
buf.reserve(needed_u16);
207208
}
208209
let new_cap_u16 = buf.capacity();
209210
let new_cap_bytes = new_cap_u16 * std::mem::size_of::<u16>();

0 commit comments

Comments
 (0)