Clean up common/ comments and the log-ring strncpy warning

Comments must not document the past or reference plan circumstances:
drop the stale pointer to a never-created audio_correlate_layout.hpp,
the "step b" plan labels, the "carved out of reserved space" history
note, and a README pointer; reword a past-tense seqlock comment to
describe the failure mode in the present.

Replace the strncpy in log_ring_push with a bounded memcpy: same
semantics (truncate + NUL), but without the C4996 deprecation warning
on every host build.
This commit is contained in:
2026-07-12 08:31:48 +02:00
parent d73b43ad0d
commit 05039ab104
4 changed files with 16 additions and 16 deletions

View File

@@ -9,6 +9,7 @@
// ever falls a whole ring behind (fine for diagnostics). POD + version-locked.
#pragma once
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <cstring>
@@ -94,15 +95,16 @@ inline void log_ring_push(LogRing& r, std::uint32_t pid, std::uint32_t level, st
LogRecord& rec = log_ring_records(&r)[idx % r.capacity];
// Seqlock write. Mark the slot in-progress (seq 0) and fence BEFORE touching the record, so a
// consumer still reading the slot's previous occupant sees seq change and bails instead of reading
// half-overwritten text; publish the new generation only after the text is fully written. Without
// this the consumer's single seq check passed before the read, so an overwrite mid-read tore it.
// half-overwritten text; publish the new generation only after the text is fully written. A single
// seq check before the consumer's copy would miss an overwrite that starts mid-read.
rec.seq.store(0, std::memory_order_relaxed);
std::atomic_thread_fence(std::memory_order_release);
rec.pid = pid;
rec.level = level;
rec.millis = millis;
std::strncpy(rec.text, text, kLogMsgLen - 1);
rec.text[kLogMsgLen - 1] = '\0';
const std::size_t len = std::min<std::size_t>(std::strlen(text), kLogMsgLen - 1);
std::memcpy(rec.text, text, len);
rec.text[len] = '\0';
std::atomic_thread_fence(std::memory_order_release);
rec.seq.store(idx + 1, std::memory_order_relaxed); // publish: generation idx is ready
}