Skip to content

Commit

Permalink
mpz toString fix
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tobey authored and John Tobey committed May 10, 2012
1 parent a9a737a commit 10198b9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/gmp-plugin.c
Expand Up @@ -1018,21 +1018,20 @@ integer_toString (TopObject *top, mpz_ptr mpp, const NPVariant *args,
if (argCount < 1)
base = 10;

else if (in_output_base (top, &args[0], &base)) {
size_t len = mpz_sizeinbase (mpp, base) + 2;
NPUTF8* s = (NPUTF8*) NPN_MemAlloc (len);
if (s) {
mpz_get_str (s, base, mpp);
if (s[0] != '-')
len--;
STRINGN_TO_NPVARIANT (s, s[len-2] ? len-1 : len-2, *result);
}
else
return oom ((NPObject*) top, result, true);
}
else
else if (!in_output_base (top, &args[0], &base)) {
return set_exception ((NPObject*) top, "invalid argument", result,
true);
}

size_t len = mpz_sizeinbase (mpp, base) + 2;
NPUTF8* s = (NPUTF8*) NPN_MemAlloc (len);
if (!s)
return oom ((NPObject*) top, result, true);

mpz_get_str (s, base, mpp);
if (s[0] != '-')
len--;
STRINGN_TO_NPVARIANT (s, s[len-2] ? len-1 : len-2, *result);
return true;
}

Expand Down

0 comments on commit 10198b9

Please sign in to comment.