diff --git a/common/web/types/src/kmx/element-string.ts b/common/web/types/src/kmx/element-string.ts index 185a24ae86..b26878f459 100644 --- a/common/web/types/src/kmx/element-string.ts +++ b/common/web/types/src/kmx/element-string.ts @@ -75,6 +75,8 @@ export class ElementString extends Array { // 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); diff --git a/developer/src/kmc-kmn/src/compiler/compiler.ts b/developer/src/kmc-kmn/src/compiler/compiler.ts index e2b2b10eda..8e3f215fc4 100644 --- a/developer/src/kmc-kmn/src/compiler/compiler.ts +++ b/developer/src/kmc-kmn/src/compiler/compiler.ts @@ -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);