cybersecurity · beginner · ~15 min
Compare a write size against the buffer capacity.
Decide whether a write would spill past the end of a fixed buffer — the check that prevents the classic overflow.
Implement int will_overflow(int write_len, int buf_size) that returns 1 if writing write_len bytes into a buf_size buffer overflows it, else 0.
write_len: number of bytes to be written.buf_size: capacity of the destination buffer.Returns int: 1 if write_len > buf_size, else 0.
will_overflow(20, 16) -> 1
will_overflow(16, 16) -> 0 (exact fit)
will_overflow(8, 16) -> 0
write_len == buf_size) does not overflow.Two ints: write_len and buf_size.
An int: 1 if write_len > buf_size, else 0.
An exact fit is not an overflow.
int will_overflow(int write_len, int buf_size) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.