Answer
A buffer overflow occurs when code accesses beyond the bounds of an array or allocated object. • Out-of-bounds reads and writes have undefined behavior. • A write can corrupt nearby data or create a security vulnerability. • Track capacity and validate lengths before copying or indexing.
💡 C Example
char buffer[8];
const char source[] = "Hello";
if (sizeof source <= sizeof buffer) {
memcpy(buffer, source, sizeof source);
}
⚡ Quick Revision
A buffer overflow is an out-of-bounds access and causes undefined behavior.