Skip to content

Commit

Permalink
Merge pull request ryanmcgrath#20 from perfectworks/master
Browse files Browse the repository at this point in the history
LineReader.hasNextLine will go to an endless loop
  • Loading branch information
Ryan McGrath committed Feb 22, 2012
2 parents 6caa8c9 + 48aa600 commit e0e9f52
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/wrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,19 @@ exports.LineReader.prototype = {
var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");

this.buffer += res[0];
if(res[1] === 0) return -1;
if(res[1] === 0) {
this.currentPosition = -1;
} else {
this.currentPosition = position + res[1];
}

this.currentPosition = position + res[1];
return this.currentPosition;
},

hasNextLine: function() {
while(this.buffer.indexOf('\n') === -1) {
this.getBufferAndSetCurrentPosition(this.currentPosition);
if(this.currentPosition === -1) return false;
if(this.buffer.length === 0) return false;
}

if(this.buffer.indexOf("\n") > -1) return true;
Expand Down

0 comments on commit e0e9f52

Please sign in to comment.