Skip to main content

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

Back to lesson: Practice: Crash Forensics