From 42d08b365502bf6c63e3abc5be892f0e57273372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Thu, 30 Jan 2003 18:35:21 +0100 Subject: [PATCH] (nettle_mpz_set_sexp): Call sexp_iterator_next on success. That means the iterator argument can't be const. Rev: src/nettle/bignum.h:1.7 Rev: src/nettle/sexp2bignum.c:1.4 --- bignum.h | 5 +++-- sexp2bignum.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bignum.h b/bignum.h index 3ba8ea5d..dce95126 100644 --- a/bignum.h +++ b/bignum.h @@ -80,8 +80,9 @@ nettle_mpz_random(mpz_t x, struct sexp_iterator; -/* If LIMIT is non-zero, the number must be at most LIMIT bits. */ +/* If LIMIT is non-zero, the number must be at most LIMIT bits. + * Implies sexp_iterator_next. */ int -nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i); +nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i); #endif /* NETTLE_BIGNUM_H_INCLUDED */ diff --git a/sexp2bignum.c b/sexp2bignum.c index f7ef6884..e75e6988 100644 --- a/sexp2bignum.c +++ b/sexp2bignum.c @@ -32,7 +32,7 @@ #include "bignum.h" int -nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i) +nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i) { if (i->type == SEXP_ATOM && i->atom_length @@ -43,8 +43,12 @@ nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i) return 0; nettle_mpz_set_str_256_s(x, i->atom_length, i->atom); + /* FIXME: How to interpret a limit for negative numbers? */ - return !limit || mpz_sizeinbase(x, 2) <= limit; + if (limit && mpz_sizeinbase(x, 2) > limit) + return 0; + + return sexp_iterator_next(i); } else return 0; -- GitLab