diff --git a/std/hl/_std/StringBuf.hx b/std/hl/_std/StringBuf.hx index 2ca291847bb..a189d98e256 100644 --- a/std/hl/_std/StringBuf.hx +++ b/std/hl/_std/StringBuf.hx @@ -41,9 +41,13 @@ } inline function __expand(need:Int):Void { - var nsize = (size * 3) >> 1; + var nsize = size + (size >> 1); + if (nsize < size) + nsize = 0x7FFF0000; if (need > nsize) nsize = need; + if (nsize <= size) + throw "StringBuf maximum capacity reached"; var b2 = new hl.Bytes(nsize); b2.blit(0, b, 0, pos); b = b2; diff --git a/tests/hlcode/src/Macro.hx b/tests/hlcode/src/Macro.hx index 53610a9e2bf..253cca18007 100644 --- a/tests/hlcode/src/Macro.hx +++ b/tests/hlcode/src/Macro.hx @@ -229,6 +229,11 @@ class Macro { // Remove source line prefix from instruction lines: ".12 @0" → "@0" trimmed = ~/^\.\d+[ \t]+/.replace(trimmed, ""); + // Normalize dynset constant in "dynset 7[@159],0" → "dynset 7[@0],0" + trimmed = ~/\bdynset (\d+)\[@(\d+)\],(\d+)/.map(trimmed, function(r) { + return "dynset " + r.matched(1) + "[@" + getGlobalId("str_" + r.matched(2)) + "]," + r.matched(3); + }); + // Normalize global IDs in "global R, G" (OGetGlobal): G is the global index trimmed = ~/\bglobal (\d+), (\d+)/.map(trimmed, function(r) { return "global " + r.matched(1) + ", " + getGlobalId(r.matched(2));