Skip to content

Commit

Permalink
Fix workspace overflow during optimization
Browse files Browse the repository at this point in the history
This patch consists of a part of 1d4b775 + vermaseren#481. Fixes vermaseren#447.

Co-authored-by: Jos Vermaseren <[email protected]>
Co-authored-by: Josh Davies <[email protected]>
  • Loading branch information
3 people committed Mar 5, 2024
1 parent 88e29f3 commit 6e1969f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sources/optimize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,20 @@ vector<WORD> Horner_tree (const WORD *expr, const vector<WORD> &order) {

// sort variables in individual terms using bubble sort
WORD *sorted = AT.WorkPointer;
LONG sumsize = 0;

for (const WORD *t=expr; *t!=0; t+=*t) {
sumsize += *t;
}
if ( sorted + sumsize > AT.WorkTop ) {
MLOCK(ErrorMessageLock);
MesPrint("=== Workspace overflow. %l bytes is not enough.",AM.WorkSize);
MesPrint("=== Change parameter WorkSpace in %s",setupfilename);
sumsize = (AT.WorkPointer-AT.WorkSpace+sumsize)*sizeof(WORD);
MesPrint("=== At least %l bytes are needed.",sumsize);
MUNLOCK(ErrorMessageLock);
Terminate(-1);
}

for (const WORD *t=expr; *t!=0; t+=*t) {
memcpy(sorted, t, *t*sizeof(WORD));
Expand Down

0 comments on commit 6e1969f

Please sign in to comment.