[Ecm-commits] r2683 - trunk

cvs commits ecm-commits at lists.gforge.inria.fr
Mon Apr 20 10:33:02 CEST 2015


Author: zimmerma
Date: 2015-04-20 10:33:02 +0200 (Mon, 20 Apr 2015)
New Revision: 2683

Modified:
   trunk/ecm.c
   trunk/stage2.c
Log:
improve coverage


Modified: trunk/ecm.c
===================================================================
--- trunk/ecm.c	2015-04-08 11:30:52 UTC (rev 2682)
+++ trunk/ecm.c	2015-04-20 08:33:02 UTC (rev 2683)
@@ -1031,9 +1031,7 @@
   root_params->d2 = 0; /* Enable automatic choice of d2 */
   if (bestD (root_params, k, dF, B2min, B2, *po2, use_ntt, maxmem, 
              (TreeFilename != NULL), modulus) == ECM_ERROR)
-    {
-      return ECM_ERROR;
-    }
+    return ECM_ERROR;
 
   /* Set default degree for Brent-Suyama extension */
   /* We try to keep the time used by the Brent-Suyama extension

Modified: trunk/stage2.c
===================================================================
--- trunk/stage2.c	2015-04-08 11:30:52 UTC (rev 2682)
+++ trunk/stage2.c	2015-04-20 08:33:02 UTC (rev 2683)
@@ -43,12 +43,8 @@
   unsigned int i, b = 0;
   mpz_t t, u;
 
-  if (n == 0)
-    {
-      mpz_set_ui (r, 1);
-      return;
-    }
-  
+  ASSERT_ALWAYS(n > 0);
+
   while (n > 2 && (n & 1) == 0)
     {
       b++;
@@ -169,8 +165,7 @@
 
   size_fd = k * (eulerphi(d) / eulerphi(m)) * (E + 1);
   fd = (listz_t) malloc (size_fd * sizeof (mpz_t));
-  if (fd == NULL)
-    return NULL;
+  ASSERT_ALWAYS(fd != NULL);
   for (i = 0; i < size_fd; i++)
     mpz_init (fd[i]);
 
@@ -267,6 +262,7 @@
       params->nr *= 6;
     }
 
+#if 0 /* commented out since not covered by unit tests */
   if (d1 % 11 == 0 &&
       d1 / params->dsieve / 11. * cost > 
       9. * params->S * log (11. * params->dsieve * d2) / 2.)
@@ -274,6 +270,7 @@
       params->dsieve *= 11;
       params->nr *= 10;
     }
+#endif
 
   params->size_fd = params->nr * (params->S + 1);
   params->next = 0;
@@ -361,13 +358,7 @@
   if (use_ntt)
     {
       mpzspm = mpzspm_init (2 * dF, modulus->orig_modulus);
-  
-      if (mpzspm == NULL)
-        {
-          outputf (OUTPUT_ERROR, "Could not initialise mpzspm, "
-                   "presumably out of memory\n");
-          return ECM_ERROR;
-        }
+      ASSERT_ALWAYS(mpzspm != NULL);
 
       outputf (OUTPUT_VERBOSE,
 	  "Using %u small primes for NTT\n", mpzspm->sp_num);
@@ -391,22 +382,14 @@
 
   F = init_list2 (dF + 1, mpz_sizeinbase (modulus->orig_modulus, 2) + 
                           3 * GMP_NUMB_BITS);
-  if (F == NULL)
-    {
-      youpi = ECM_ERROR;
-      goto clear_i0;
-    }
+  ASSERT_ALWAYS(F != NULL);
 
   sizeT = 3 * dF + list_mul_mem (dF);
   if (dF > 3)
     sizeT += dF;
   T = init_list2 (sizeT, 2 * mpz_sizeinbase (modulus->orig_modulus, 2) + 
                          3 * GMP_NUMB_BITS);
-  if (T == NULL)
-    {
-      youpi = ECM_ERROR;
-      goto clear_F;
-    }
+  ASSERT_ALWAYS(T != NULL);
   H = T;
 
   /* needs dF+1 cells in T */
@@ -437,25 +420,12 @@
   if (TreeFilename == NULL)
     {
       Tree = (listz_t*) malloc (lgk * sizeof (listz_t));
-      if (Tree == NULL)
-        {
-          outputf (OUTPUT_ERROR, "Error: not enough memory\n");
-          youpi = ECM_ERROR;
-          goto clear_T;
-        }
+      ASSERT_ALWAYS(Tree != NULL);
       for (i = 0; i < lgk; i++)
         {
           Tree[i] = init_list2 (dF, mpz_sizeinbase (modulus->orig_modulus, 2) 
                                     + GMP_NUMB_BITS);
-          if (Tree[i] == NULL)
-            {
-              /* clear already allocated Tree[i] */
-              while (i)
-              clear_list (Tree[--i], dF);
-              free (Tree);
-              youpi = ECM_ERROR;
-              goto clear_T;
-            }
+          ASSERT_ALWAYS(Tree[i] != NULL);
         }
     }
   else
@@ -471,11 +441,7 @@
     {
       FILE *TreeFile;
       char *fullname = (char *) malloc (strlen (TreeFilename) + 1 + 2 + 1);
-      if (fullname == NULL)
-        {
-          fprintf (stderr, "Cannot allocate memory in stage2\n");
-          exit (1);
-        }
+      ASSERT_ALWAYS(fullname != NULL);
       
       for (i = lgk; i > 0; i--)
         {
@@ -564,11 +530,7 @@
          but we need one more for TUpTree */
       invF = init_list2 (dF + 1, mpz_sizeinbase (modulus->orig_modulus, 2) + 
                                  2 * GMP_NUMB_BITS);
-      if (invF == NULL)
-	{
-	  youpi = ECM_ERROR;
-	  goto free_Tree_i;
-	}
+      ASSERT_ALWAYS(invF != NULL);
       st = cputime ();
       
       if (use_ntt)
@@ -607,11 +569,7 @@
   */
   G = init_list2 (dF, mpz_sizeinbase (modulus->orig_modulus, 2) + 
                       3 * GMP_NUMB_BITS);
-  if (G == NULL)
-    {
-      youpi = ECM_ERROR;
-      goto clear_invF;
-    }
+  ASSERT_ALWAYS(G != NULL);
 
   st = cputime ();
   rootsG_state = ecm_rootsG_init (f, (curve *) X, root_params, dF, k, 
@@ -824,11 +782,7 @@
     {
       /* Unlink any treefiles still in use */
       char *fullname = (char *) malloc (strlen (TreeFilename) + 1 + 2 + 1);
-      if (fullname == NULL)
-        {
-          fprintf (stderr, "Cannot allocate memory in stage2\n");
-          exit (1);
-        }
+      ASSERT_ALWAYS(fullname != NULL);
       for (i = 0; i < treefiles_used; i++)
         {
           sprintf (fullname, "%s.%lu", TreeFilename, i);



More information about the Ecm-commits mailing list