shithub: libmujs

Download patch

ref: 6fd45b83747aba518399bed705080a7f4312e77b
parent: fac3f501e441f946f9d90eb566439920f5fe1bfd
author: Tor Andersson <tor@ccxvii.net>
date: Sat Jan 25 17:56:36 EST 2014

Guard String.fromCharCode malloc with try/endtry.

--- a/jsstring.c
+++ b/jsstring.c
@@ -77,8 +77,15 @@
 {
 	int i;
 	Rune c;
-	char *s = malloc(argc * UTFmax + 1), *p = s;
-	// TODO: guard malloc with try/catch
+	char *s, *p;
+
+	s = p = malloc(argc * UTFmax + 1);
+
+	if (js_try(J)) {
+		free(s);
+		js_throw(J);
+	}
+
 	for (i = 1; i <= argc; ++i) {
 		c = js_tointeger(J, i); // TODO: ToUInt16()
 		p += runetochar(p, &c);
@@ -85,6 +92,8 @@
 	}
 	*p = 0;
 	js_pushstring(J, s);
+
+	js_endtry(J);
 	free(s);
 	return 1;
 }