Skip to content

Commit

Permalink
fix: always pop current element in readStringOpt and readBufferOpt
Browse files Browse the repository at this point in the history
In the case of null elements, the current stack element wasn't popped
which caused incorrect processing of the subsequent tuple elements.
  • Loading branch information
anton-trunov committed Oct 7, 2024
1 parent 9c1b8f7 commit bf64d50
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/tuple/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,16 @@ export class TupleReader {
}

readBufferOpt() {
let popped = this.peek();
if (popped.type === 'null') {
let r = this.readCellOpt();
if (r !== null) {
let s = r.beginParse();
if (s.remainingRefs !== 0 || s.remainingBits % 8 !== 0) {
throw Error('Not a buffer');
}
return s.loadBuffer(s.remainingBits / 8);
} else {
return null;
}
let s = this.readCell().beginParse();
if (s.remainingRefs !== 0) {
throw Error('Not a buffer');
}
if (s.remainingBits % 8 !== 0) {
throw Error('Not a buffer');
}
return s.loadBuffer(s.remainingBits / 8);
}
}

readString() {
Expand All @@ -205,11 +203,13 @@ export class TupleReader {
}

readStringOpt() {
let popped = this.peek();
if (popped.type === 'null') {
let r = this.readCellOpt();
if (r !== null) {
let s = r.beginParse();
return s.loadStringTail();
} else {
return null;
}
let s = this.readCell().beginParse();
return s.loadStringTail();
}
}
}

0 comments on commit bf64d50

Please sign in to comment.