cybersecurity · intermediate · ~15 min
Detect integer multiplication overflow.
Implement int safe_mul(int a, int b, int *out) storing a*b in *out and returning 0 if it fits in an int, or returning -1 on overflow (compute in a wider type to detect it).
#include <limits.h>
int safe_mul(int a, int b, int *out) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.