Skip to content

Commit 3c74c38

Browse files
committed
make pointer accept 0 offset
1 parent 39912a8 commit 3c74c38

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/binary_parser.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export class Parser {
286286
alias?: string;
287287
useContextVariables = false;
288288

289-
constructor() {}
289+
constructor() { }
290290

291291
static start() {
292292
return new Parser();
@@ -706,7 +706,7 @@ export class Parser {
706706
}
707707

708708
pointer(varName: string, options: ParserOptions): this {
709-
if (!options.offset) {
709+
if (options.offset == null) {
710710
throw new Error("offset is required for pointer.");
711711
}
712712

@@ -1118,8 +1118,7 @@ export class Parser {
11181118
if (rem) {
11191119
const mask = -1 >>> (32 - rem);
11201120
ctx.pushCode(
1121-
`${parser.varName} = (${val} & 0x${mask.toString(16)}) << ${
1122-
length - rem
1121+
`${parser.varName} = (${val} & 0x${mask.toString(16)}) << ${length - rem
11231122
};`,
11241123
);
11251124
length -= rem;
@@ -1131,8 +1130,7 @@ export class Parser {
11311130
const mask = -1 >>> (32 - length);
11321131

11331132
ctx.pushCode(
1134-
`${parser.varName} ${
1135-
length < (parser.options.length as number) ? "|=" : "="
1133+
`${parser.varName} ${length < (parser.options.length as number) ? "|=" : "="
11361134
} ${val} >> ${offset} & 0x${mask.toString(16)};`,
11371135
);
11381136

0 commit comments

Comments
 (0)