kobalicek / mathpresso

Mathematical Expression Parser and JIT Compiler
Other
141 stars 16 forks source link

"Custom Functions" lead into assert #8

Closed JuergenWurth closed 8 years ago

JuergenWurth commented 8 years ago

Thanks for the nice project. During finding out, whether is can use it within one of my (so far not official) projects, I found a bug in mathpresso.cpp:

/*349*/     if (sym != NULL) \ 
/*350*/       return MATHPRESSO_TRACE_ERROR(kErrorSymbolAlreadyExists); \ 
/*351*/     \ 
/*352*/     sym = d->_builder.newSymbol(StringRef(name, nlen), hVal, kAstSymbolVariable, kAstScopeGlobal); \ 
/*353*/     if (sym == NULL) \ 

should be changed to:

/*349*/     if (sym != NULL) \ 
/*350*/       return MATHPRESSO_TRACE_ERROR(kErrorSymbolAlreadyExists); \ 
/*351*/     \ 
/*352*/     sym = d->_builder.newSymbol(StringRef(name, nlen), hVal, type, kAstScopeGlobal); \ 
/*353*/     if (sym == NULL) \

otherwise it asserts "not a function" and, if the assert was skipped, will "syntax error" for the "(" after the function name in an expression.

BR, Juergen

kobalicek commented 8 years ago

Thanks, seems you are right. I will try to cover this by a test-case.

kobalicek commented 8 years ago

Should be fixed, please check it out.