beltoforion / muparserx

A C++ Library for Parsing Expressions with Strings, Complex Numbers, Vectors, Matrices and more.
http://beltoforion.de/en/muparserx
BSD 2-Clause "Simplified" License
135 stars 60 forks source link

Segfault in parser/mpIToken.cpp:185 #63

Closed nasailja closed 9 years ago

nasailja commented 9 years ago

Giving 0-0-eye() to:

#include "iostream"
#include "string"
#include "mpParser.h"
int main() {
    std::string expression;
    std::cin >> expression;
    mup::ParserX parser(mup::pckCOMMON | mup::pckNON_COMPLEX | mup::pckMATRIX | mup::pckUNIT);
    parser.SetExpr(expression);
    try {
        const auto evaluated = parser.Eval().GetArray();
    } catch (...) {}
    return 0;
}

using latest mupx results in a segfault:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x0000000000000000 in ?? ()
(gdb) up
#1  0x0000000100083017 in mup::IToken::ToString (this=0x100205528) at parser/mpIToken.cpp:185
185     return AsciiDump();
(gdb) 
#2  0x00000001000dc236 in mup::FunMatrixEye::Eval (this=<value temporarily unavailable, due to optimizations>, ret=@0x100205528, a_pArg=0x100205528, argc=<value temporarily unavailable, due to optimizations>) at parser/mpFuncMatrix.cpp:183
183         n = (argc == 1) ? m : a_pArg[1]->GetInteger();
(gdb) 
#3  0x00000001000281dd in mup::ParserXBase::ParseFromRPN (this=0x7fff5fbff7c0) at parser/mpParserBase.cpp:1113
1113                        pFun->Eval(val, &val, nArgs);
(gdb) 
#4  0x0000000100001092 in main () at muparserx.cpp:10
10          const auto evaluated = parser.Eval().GetArray();
nasailja commented 9 years ago

Another one 0<0-0--eye()

beltoforion commented 9 years ago

Fixed in 4.0.3

nasailja commented 9 years ago

That was fast, thanks!

beltoforion commented 9 years ago

The same issue also affected ones() and zeros() function. I commited 4.0.4 to deal with that