Skip to content

Commit 7385f41

Browse files
committed
improve range check in VectorTileLayer#getFeature
1 parent 9cee21a commit 7385f41

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

lib/vectortilelayer.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export class VectorTileLayer {
2121

2222
// return feature `i` from this layer as a `VectorTileFeature`
2323
feature(i) {
24-
if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds');
25-
26-
this._pbf.pos = this._features[i];
27-
28-
const end = this._pbf.readVarint() + this._pbf.pos;
24+
const pos = this._features[i];
25+
if (pos == null) throw new RangeError(`feature index ${i} out of bounds`);
26+
this._pbf.pos = pos;
27+
const end = this._pbf.readVarint() + pos;
2928
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
3029
}
3130
}

0 commit comments

Comments
 (0)