Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error "Sorted function argument too long" #289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions sources/polywrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ WORD *poly_gcd(PHEAD WORD *a, WORD *b, WORD fit) {
if ( fit ) {
if ( newsize*sizeof(WORD) >= (size_t)(AM.MaxTer) ) {
MLOCK(ErrorMessageLock);
MesPrint("poly_gcd: Term too complex. Maybe increasing MaxTermSize can help");
MesPrint("poly_gcd: Term too complex (%d words). Maybe increasing MaxTermSize (%d words) can help",
newsize, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
Terminate(-1);
}
Expand Down Expand Up @@ -351,7 +352,8 @@ WORD *poly_divmod(PHEAD WORD *a, WORD *b, int divmod, WORD fit) {
if ( fit ) {
if ( ressize*sizeof(WORD) > (size_t)(AM.MaxTer) ) {
MLOCK(ErrorMessageLock);
MesPrint("poly_divmod: Term too complex. Maybe increasing MaxTermSize can help");
MesPrint("poly_divmod: Term too complex (%d words). Maybe increasing MaxTermSize (%d words) can help",
ressize, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
Terminate(-1);
}
Expand Down Expand Up @@ -670,8 +672,8 @@ WORD *poly_ratfun_add (PHEAD WORD *t1, WORD *t2) {
if (num.size_of_form_notation() + den.size_of_form_notation() + 3 >= AM.MaxTer/(int)sizeof(WORD)) {
MLOCK(ErrorMessageLock);
MesPrint ("ERROR: PolyRatFun doesn't fit in a term");
MesPrint ("(1) num size = %d, den size = %d, MaxTer = %d",num.size_of_form_notation(),
den.size_of_form_notation(),AM.MaxTer);
MesPrint ("(1) num size = %d, den size = %d, MaxTermSize = %d words",num.size_of_form_notation(),
den.size_of_form_notation(),AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
Terminate(-1);
}
Expand Down Expand Up @@ -815,8 +817,8 @@ int poly_ratfun_normalize (PHEAD WORD *term) {
if (num1.size_of_form_notation() + den1.size_of_form_notation() + 3 >= AM.MaxTer/(int)sizeof(WORD)) {
MLOCK(ErrorMessageLock);
MesPrint ("ERROR: PolyRatFun doesn't fit in a term");
MesPrint ("(2) num size = %d, den size = %d, MaxTer = %d",num1.size_of_form_notation(),
den1.size_of_form_notation(),AM.MaxTer);
MesPrint ("(2) num size = %d, den size = %d, MaxTermSize = %d words",num1.size_of_form_notation(),
den1.size_of_form_notation(),AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
Terminate(-1);
}
Expand Down Expand Up @@ -973,7 +975,8 @@ WORD *poly_factorize (PHEAD WORD *argin, WORD *argout, bool with_arghead, bool i
// check size
if (len >= AM.MaxTer) {
MLOCK(ErrorMessageLock);
MesPrint ("ERROR: factorization doesn't fit in a term");
MesPrint ("ERROR: factorization doesn't fit in a term (len = %d, MaxTermSize = %d words)",
len/sizeof(WORD), AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
Terminate(-1);
}
Expand Down
40 changes: 32 additions & 8 deletions sources/proces.c
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,12 @@ WORD InFunction(PHEAD WORD *term, WORD *termout)
*m++ = 3;
r = term + *term;
while ( t < r ) *m++ = *t++;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) goto TooLarge;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
goto TooLarge;
}
*termout = WORDDIF(m,termout);
return(0);
}
Expand Down Expand Up @@ -2279,7 +2284,12 @@ WORD InFunction(PHEAD WORD *term, WORD *termout)
r = term + *term;
t = v;
while ( t < r ) *m++ = *t++;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) goto TooLarge;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
goto TooLarge;
}
*termout = WORDDIF(m,termout);
AR.DeferFlag = olddefer;
AN.ncmod = oldncmod;
Expand Down Expand Up @@ -2463,7 +2473,12 @@ WORD InFunction(PHEAD WORD *term, WORD *termout)
r = term + *term;
t = v;
while ( t < r ) *m++ = *t++;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) goto TooLarge;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
goto TooLarge;
}
*termout = WORDDIF(m,termout);
AR.DeferFlag = olddefer;
AN.ncmod = oldncmod;
Expand Down Expand Up @@ -2505,7 +2520,12 @@ WORD InFunction(PHEAD WORD *term, WORD *termout)
from++; /* Skip our function */
r = term + *term;
while ( from < r ) *m++ = *from++;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) goto TooLarge;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
goto TooLarge;
}
*termout = WORDDIF(m,termout);
return(0);
}
Expand Down Expand Up @@ -2646,7 +2666,12 @@ wrongtype:;
term += *term;
while ( from < term ) *m++ = *from++;
if ( sign < 0 ) m[-1] = -m[-1];
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) goto TooLarge;
if ( (m-termout) > (LONG)(AM.MaxTer/sizeof(WORD)) ) {
MLOCK(ErrorMessageLock);
MesPrint("Output term too large (%d words) (MaxTermSize: %d words)", m-termout, AM.MaxTer/sizeof(WORD));
MUNLOCK(ErrorMessageLock);
goto TooLarge;
}
*termout = m - termout;
AN.ncmod = oldncmod;
return(0);
Expand Down Expand Up @@ -2690,7 +2715,6 @@ wrongtype:;

TooLarge:
MLOCK(ErrorMessageLock);
MesPrint("Output term too large. Try to increase MaxTermSize in the setup.");
MesCall("InFunction");
MUNLOCK(ErrorMessageLock);
SETERROR(-1)
Expand Down Expand Up @@ -2799,7 +2823,7 @@ ComAct: if ( t < u ) do { *m++ = *t++; } while ( t < u );
*termout = WORDDIF(m,termout);
if ( (*termout)*((LONG)sizeof(WORD)) > AM.MaxTer ) {
MLOCK(ErrorMessageLock);
MesPrint("Term too complex during substitution. MaxTermSize of %l is too small",AM.MaxTer);
MesPrint("Term too complex during substitution (%d words). MaxTermSize (%l words) is too small.", *termout, AM.MaxTer/(LONG)sizeof(WORD) );
goto InsCall2;
}
AT.WorkPointer = coef;
Expand Down Expand Up @@ -5735,7 +5759,7 @@ WORD PolyFunMul(PHEAD WORD *term)
*AT.WorkPointer = n1 = WORDDIF(t,AT.WorkPointer);
if ( n1*((LONG)sizeof(WORD)) > AM.MaxTer ) {
MLOCK(ErrorMessageLock);
MesPrint("Term too complex. Maybe increasing MaxTermSize can help");
MesPrint("Term too complex (%d words). MaxTermSize (%l words) is too small.", n1, AM.MaxTer/(LONG)sizeof(WORD) );
goto PolyCall2;
}
m = term; t = AT.WorkPointer;
Expand Down
13 changes: 11 additions & 2 deletions sources/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,12 @@ LONG EndSort(PHEAD WORD *buffer, int par)
while ( ( t = *ss++ ) != 0 ) {
j = *t;
if ( ( sSpace += j ) > AM.MaxTer/((LONG)sizeof(WORD)) ) {
/* Too big! Get the total size for useful error message */
while ( ( t = *ss++ ) != 0 ) {
sSpace += *t;
}
MLOCK(ErrorMessageLock);
MesPrint("Sorted function argument too long.");
MesPrint("Sorted function argument too long (%d words). Increase MaxTermSize (%l words).", sSpace, AM.MaxTer/((LONG)sizeof(WORD)));
MUNLOCK(ErrorMessageLock);
retval = -1; goto RetRetval;
}
Expand Down Expand Up @@ -992,7 +996,12 @@ LONG EndSort(PHEAD WORD *buffer, int par)
to = buffer;
if ( to >= AT.WorkSpace && to < AT.WorkTop && to+j > AT.WorkTop )
goto WorkSpaceError;
if ( j > AM.MaxTer ) goto TooLarge;
if ( j > AM.MaxTer ) {
MLOCK(ErrorMessageLock);
MesPrint("Encountered term of size: %d words.", j/(LONG)sizeof(WORD) );
MUNLOCK(ErrorMessageLock);
goto TooLarge;
}
NCOPY(to,t,j);
}
}
Expand Down
1 change: 1 addition & 0 deletions sources/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,7 @@ VOID *Malloc1(LONG size, const char *messageifwrong)
#ifndef MALLOCDEBUG
MLOCK(ErrorMessageLock);
#endif
MesPrint("Attempted to allocate %l bytes.", size);
Error1("No memory while allocating ",(UBYTE *)messageifwrong);
#ifndef MALLOCDEBUG
MUNLOCK(ErrorMessageLock);
Expand Down
Loading