@@ -410,14 +410,16 @@ static int32_t get_nvars(const char *fn)
410410 * \return 1 if the line is empty, else 0
411411 */
412412static inline int is_line_empty (const char * line , const char delim ) {
413- while (* line != '\0' && * line != ',' ) {
413+ while (* line != '\0' && * line != delim ) {
414414 if (!isspace (* line ))
415415 return 0 ;
416416 line ++ ;
417417 }
418418 return 1 ;
419419}
420420
421+ static void trim_polynomial (char * poly );
422+
421423static int32_t get_ngenerators (char * fn )
422424{
423425 int32_t ngens = 0 ;
@@ -430,11 +432,18 @@ static int32_t get_ngenerators(char *fn)
430432 || getline (& line , & len , fh ) == -1 )
431433 ngens = -1 ;
432434
433- /* go through subsequent lines, not counting empty ones */
434- else
435- while (getdelim (& line , & len , ',' , fh ) != -1 )
436- if (! is_line_empty (line , ',' ))
435+ /* go through subsequent lines, not counting empty or zero ones */
436+ else {
437+ while (getdelim (& line , & len , ',' , fh ) != -1 ) {
438+ if (is_line_empty (line , ',' )) {
439+ continue ;
440+ }
441+ trim_polynomial (line );
442+ if (strcmp (line , "0" ) != 0 ) {
437443 ngens ++ ;
444+ }
445+ }
446+ }
438447
439448 free (line );
440449 fclose (fh );
@@ -630,6 +639,10 @@ static void get_nterms_and_all_nterms(FILE *fh,
630639 }
631640 remove_newlines (line , & len );
632641 trim_polynomial (line );
642+ if (strcmp (line , "0" ) == 0 ) {
643+ i -- ;
644+ continue ;
645+ }
633646 * nterms = get_number_of_terms (line );
634647 gens -> lens [i ] = * nterms ;
635648 * all_nterms += * nterms ;
@@ -747,6 +760,11 @@ static int get_coefficient_ff_and_term_from_line(char *line, int32_t nterms,
747760 }
748761 }
749762 iv_tmp %= field_char ;
763+ if (iv_tmp == 0 ) {
764+ fprintf (stderr , "Error when parsing term %s (coefficient cannot be 0 modulo %d).\n" , term , field_char );
765+ free (term );
766+ return 1 ;
767+ }
750768 if (iv_tmp < 0 ) {
751769 iv_tmp += field_char ; //MS change int -> long int
752770 }
@@ -765,6 +783,11 @@ static int get_coefficient_ff_and_term_from_line(char *line, int32_t nterms,
765783 }
766784 }
767785 cf_tmp %= field_char ;
786+ if (cf_tmp == 0 ) {
787+ fprintf (stderr , "Error when parsing term %s (coefficient cannot be 0 modulo %d).\n" , term , field_char );
788+ free (term );
789+ return 1 ;
790+ }
768791 if (cf_tmp < 0 ) {
769792 cf_tmp += field_char ;
770793 }
@@ -894,6 +917,10 @@ static void get_coeffs_and_exponents_ff32(FILE *fh, nelts_t all_nterms,
894917 }
895918 remove_newlines (line , & len );
896919 trim_polynomial (line );
920+ if (strcmp (line , "0" ) == 0 ) {
921+ i -- ;
922+ continue ;
923+ }
897924 if (get_coefficient_ff_and_term_from_line (line , gens -> lens [i ], gens -> field_char ,
898925 gens , pos )){
899926 fprintf (stderr , "Error when reading file (exit but things need to be free-ed)\n" );
@@ -937,6 +964,10 @@ static void get_coeffs_and_exponents_mpz(FILE *fh, nelts_t all_nterms,
937964 }
938965 remove_newlines (line , & len );
939966 trim_polynomial (line );
967+ if (strcmp (line , "0" ) == 0 ) {
968+ i -- ;
969+ continue ;
970+ }
940971 if (get_coefficient_mpz_and_term_from_line (line , gens -> lens [i ], gens -> field_char ,
941972 gens , pos )){
942973 fprintf (stderr , "Error when reading file (exit but things need to be free-ed)\n" );
0 commit comments