fix: mem limiter for invalid ranges

This commit is contained in:
Yang Jun
2026-03-22 10:24:03 +08:00
committed by Harttle
parent 1b85fdaa9c
commit 95ddefc056
+7 -5
View File
@@ -9,12 +9,14 @@ export class Limiter {
this.limit = limit this.limit = limit
} }
use (count: number) { use (count: number) {
count = +count || 0 if (+count > 0) {
assert(this.base + count <= this.limit, this.message) assert(this.base + +count <= this.limit, this.message)
this.base += count this.base += +count
}
} }
check (count: number) { check (count: number) {
count = +count || 0 if (+count > 0) {
assert(count <= this.limit, this.message) assert(+count <= this.limit, this.message)
}
} }
} }