fix unsigned integer overflow when number of rows is 0