diff --git a/src/scripting/smjs/cache_object.c b/src/scripting/smjs/cache_object.c index f23883c75..e62f6e0e1 100644 --- a/src/scripting/smjs/cache_object.c +++ b/src/scripting/smjs/cache_object.c @@ -113,12 +113,9 @@ jsval_to_Latin1(JSContext *ctx, JS::HandleValue hvp, size_t *length) /* Memory must be freed in caller */ JSString *st = JS::ToString(ctx, hvp); JS::UniqueChars chars = JS_EncodeStringToLatin1(ctx, st); + *length = JS_GetStringLength(st); - if (length) { - *length = JS_GetStringLength(st); - } - - return null_or_stracpy(chars.get()); + return memacpy(chars.get(), *length); } static bool