mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-06 07:37:40 +00:00
fix(developer): fix an additional issue on illegal UnicodeSets
- update comments per review comments - improve logic of checks around malloc
This commit is contained in:
parent
18ba46d874
commit
baeb3c80fc
2 changed files with 11 additions and 9 deletions
|
|
@ -75,6 +75,8 @@ export class ElementString extends Array<ElemElement> {
|
|||
// TODO-LDML: err on max buffer size
|
||||
const needRanges = sections.usetparser.sizeUnicodeSet(item.segment);
|
||||
if (needRanges < 0) {
|
||||
// Note that sizeUnicodeSet() already will notify via callback if there's an
|
||||
// error. So we can just exit here.
|
||||
return null; // UnicodeSet error
|
||||
}
|
||||
const uset = sections.usetparser.parseUnicodeSet(item.segment, needRanges);
|
||||
|
|
|
|||
|
|
@ -551,18 +551,18 @@ export class KmnCompiler implements KeymanCompiler, UnicodeSetParser {
|
|||
return null;
|
||||
}
|
||||
|
||||
// TODO-LDML: Catch OOM
|
||||
const buf = this.wasmExports.malloc(rangeCount * 2 * Module.HEAPU32.BYTES_PER_ELEMENT);
|
||||
// fix \u1234 pattern format
|
||||
pattern = KmnCompiler.fixNewPattern(pattern);
|
||||
/** If <= 0: return code. If positive: range count */
|
||||
if (buf < 0) {
|
||||
throw new RangeError(`Internal error: wasm malloc() returned ${buf}`);
|
||||
}
|
||||
if ((rangeCount*2) < 0) {
|
||||
if ((rangeCount * 2) < 0) {
|
||||
throw new RangeError(`Internal error: negative rangeCount * 2 = ${rangeCount * 2}`);
|
||||
}
|
||||
const buf = this.wasmExports.malloc(rangeCount * 2 * Module.HEAPU32.BYTES_PER_ELEMENT);
|
||||
if (buf <= 0) {
|
||||
// out of memory will return zero.
|
||||
throw new RangeError(`Internal error: wasm malloc() returned ${buf}`);
|
||||
}
|
||||
// fix \u1234 pattern format
|
||||
pattern = KmnCompiler.fixNewPattern(pattern);
|
||||
const rc = Module.kmcmp_parseUnicodeSet(pattern, buf, rangeCount * 2);
|
||||
/** If <= 0: error return code. If positive: it's a range count */
|
||||
if (rc >= 0) {
|
||||
const ranges = [];
|
||||
const startu = (buf / Module.HEAPU32.BYTES_PER_ELEMENT);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue