From 2618eea4f67e72fa17db39d40ab1256963aafc90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Wed, 11 Feb 1998 04:32:44 +0100
Subject: [PATCH] * modules/Gmp/mpz_glue.c (low_get_digits): Fixed handling of
 base 256. This function should not return any leading zeros.

Rev: src/modules/Gmp/mpz_glue.c:1.28
---
 src/modules/Gmp/mpz_glue.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/modules/Gmp/mpz_glue.c b/src/modules/Gmp/mpz_glue.c
index 1a1390a8d8..d23225f9c9 100644
--- a/src/modules/Gmp/mpz_glue.c
+++ b/src/modules/Gmp/mpz_glue.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: mpz_glue.c,v 1.27 1998/01/30 16:40:03 grubba Exp $");
+RCSID("$Id: mpz_glue.c,v 1.28 1998/02/11 03:32:44 nisse Exp $");
 #include "gmp_machine.h"
 
 #if !defined(HAVE_LIBGMP)
@@ -190,12 +190,14 @@ static struct pike_string *low_get_digits(MP_INT *mpz, int base)
 
     /* lets optimize this /Mirar & Per */
 
-    len = mpz->_mp_size*sizeof(mp_limb_t);
+    /* len = mpz->_mp_size*sizeof(mp_limb_t); */
+    /* This function should not return any leading zeros. /Nisse */
+    len = (mpz_sizeinbase(mpz, 2) + 7) / 8;
     s = begin_shared_string(len);
 
     src=mpz->_mp_d;
     dst=s->str+s->len;
-    while (len)
+    while (len > 0)
     {
        mp_limb_t x=*(src++);
        for (i=0; i<sizeof(mp_limb_t); i++)
-- 
GitLab