backend: fix potential divide-by-zero