Practice ยท 2 of 3
Fix: Unguarded Input
safe_div(int a, int b) crashes on b == 0 (and on a NULL result slot). Fix it to return 1 and write the quotient on success, or 0 and leave *out untouched when b == 0 or out == NULL.
``c
int safe_div(int a, int b, int *out) {
*out = a / b;
return 1;
}
``
Difficulty: beginner
Press Submit to check your solution.
Back to lesson: Practice: Crash Forensics