fixes error propagation in optimize.c
Merge pull request #2514 from WalterBright/fix-error-prop

fixes error propagation in optimize.c