aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 10:37:19 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 10:37:19 +1000
commit46d9777cbb610079019266510c284c8c5791222b (patch)
treed1a6b761124d5afefd16a665230443ec09f62ee2 /src
parent02cc918af02b60f65c2622a2ee09e033f52d69b6 (diff)
downloadfengari-46d9777cbb610079019266510c284c8c5791222b.tar.gz
fengari-46d9777cbb610079019266510c284c8c5791222b.tar.bz2
fengari-46d9777cbb610079019266510c284c8c5791222b.zip
src/lstrlib.js: Always return a new string from num2straux
It may get mutated in lua_number2strx
Diffstat (limited to 'src')
-rw-r--r--src/lstrlib.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 1397039..8bc2b0e 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -97,11 +97,11 @@ const adddigit = function(buff, n, x) {
const num2straux = function(x) {
/* if 'inf' or 'NaN', format it like '%g' */
if (Object.is(x, Infinity))
- return lua.to_luastring('inf', true);
+ return lua.to_luastring('inf', true).slice(0);
else if (Object.is(x, -Infinity))
- return lua.to_luastring('-inf', true);
+ return lua.to_luastring('-inf', true).slice(0);
else if (Number.isNaN(x))
- return lua.to_luastring('nan', true);
+ return lua.to_luastring('nan', true).slice(0);
else if (x === 0) { /* can be -0... */
/* create "0" or "-0" followed by exponent */
let zero = sprintf(luaconf.LUA_NUMBER_FMT + "x0p+0", x).split('').map(e => e.charCodeAt(0));