mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-08 01:36:46 +08:00
- Change: explicit buffer(char const & c) → explicit buffer(char & c)
- Remove dangerous const_cast in implementation
- Before: buffer(const_cast<char*>(&c), 1) [UB if c is truly const]
- After: buffer(&c, 1) [safe, requires non-const char]
- Prevents undefined behavior from modifying compile-time constants
- Constructor now correctly requires mutable char reference
- Aligns with buffer's mutable data semantics
The previous implementation with const_cast could lead to:
- Modifying string literals (undefined behavior)
- Modifying const variables (undefined behavior)
- Runtime crashes or data corruption
Example of prevented misuse:
buffer buf('X'); // Now: compile error ✓
char c = 'X';
buffer buf(c); // Now: works correctly ✓
const char cc = 'Y';
buffer buf(cc); // Now: compile error ✓
|
||
|---|---|---|
| .. | ||
| libipc | ||