cybersecurity · intermediate · ~15 min
Detect size_t addition wrap-around.
Implement int safe_add_size(size_t a, size_t b, size_t *out) storing a+b in *out and returning 0, or -1 if the unsigned addition would wrap past SIZE_MAX.
#include <stdint.h>
#include <stddef.h>
int safe_add_size(size_t a, size_t b, size_t *out) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.