Skip to content

Commit fe0e8c8

Browse files
LakeByTheWoodsandrewrk
authored andcommitted
Tokenizer: Copy optional tokens prior to being set to null #3737 (#3910)
* Tokenizer: Copy optional tokens prior to being set to null #3737 * Add TODO comments, reminder to audit copying optional pattern.
1 parent 0f09ff4 commit fe0e8c8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/std/json.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ pub const TokenStream = struct {
886886

887887
pub fn next(self: *TokenStream) Error!?Token {
888888
if (self.token) |token| {
889+
// TODO: Audit this pattern once #2915 is closed
889890
const copy = token;
890891
self.token = null;
891892
return copy;

lib/std/zig/tokenizer.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,10 @@ pub const Tokenizer = struct {
411411

412412
pub fn next(self: *Tokenizer) Token {
413413
if (self.pending_invalid_token) |token| {
414+
// TODO: Audit this pattern once #2915 is closed
415+
const copy = token;
414416
self.pending_invalid_token = null;
415-
return token;
417+
return copy;
416418
}
417419
const start_index = self.index;
418420
var state = State.Start;
@@ -1265,8 +1267,10 @@ pub const Tokenizer = struct {
12651267

12661268
if (result.id == Token.Id.Eof) {
12671269
if (self.pending_invalid_token) |token| {
1270+
// TODO: Audit this pattern once #2915 is closed
1271+
const copy = token;
12681272
self.pending_invalid_token = null;
1269-
return token;
1273+
return copy;
12701274
}
12711275
}
12721276

0 commit comments

Comments
 (0)