Fixed signed/unsigned comparison

Fixes #503, though not tested on Windows.