diff --git a/bignum.h b/bignum.h
index 3ba8ea5deb5f5af83d62f475de71d0582480d474..dce95126fb6677ee0840ff1822b1a9cfa5c4be0c 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 f7ef68843f9feb6003c403d01776234503442578..e75e6988c6a3d6e626023dbfe98d1615b14512d6 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;