Fix mis-handling of next-line calculation that caused programs to loop
endlessly. [BugId: 170, 165]