A variety of small tweaks and fixes. Make mpmont etc. return errors
[u/mdw/catacomb] / f-niceprime.c
index a6191da..ce96977 100644 (file)
@@ -138,7 +138,7 @@ static const field_ops fops = {
  *
  * Arguments:  @mp *p@ = the characteristic of the field
  *
- * Returns:    A pointer to the field.
+ * Returns:    A pointer to the field, or null.
  *
  * Use:                Creates a field structure for a prime field of size %$p$%,
  *             using efficient reduction for nice primes.
@@ -152,7 +152,10 @@ field *field_niceprime(mp *p)
   f->f.one = MP_ONE;
   f->f.nbits = mp_bits(p);
   f->f.noctets = (f->f.nbits + 7) >> 3;
-  mpreduce_create(&f->r, p);
+  if (mpreduce_create(&f->r, p)) {
+    DESTROY(f);
+    return (0);
+  }
   f->f.m = f->r.p;
   return (&f->f);
 }