substr_compare(): Allow zero length comparison

Analogous to how `strncmp()` handles a zero length comparison, `substr_compare()` with a zero length should return `0` as well.

Example:

    substr_compare("abc", "a", 0, 0); // 0
    substr_compare("abc", "a", 0, -1); // false (with warning)

This patch also cleans up logic prior to bug #33605