backend: fix potential division-by-zero