Check for row >= 0 and fix compiler warnings
(cherry picked from commit ba2b3108c404e62381180926c6830d2853a166dc)