From: thurston Date: Sat, 10 Feb 2007 17:50:23 +0000 (+0000) Subject: Fixed the null dereference and consequential segfault which occurred when X-Git-Tag: 2.0_alpha~394 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b566724ab8f5776683f630b92466e1934f015ae;p=external%2Fragel.git Fixed the null dereference and consequential segfault which occurred when trying to create empty machines with [] and // and /a[]b/. git-svn-id: http://svn.complang.org/ragel/trunk@92 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/ragel/parsetree.cpp b/ragel/parsetree.cpp index 9764c7f..6ff6fc5 100644 --- a/ragel/parsetree.cpp +++ b/ragel/parsetree.cpp @@ -1700,7 +1700,7 @@ Factor::~Factor() delete reItem; break; case RegExprType: - delete regExp; + delete regExpr; break; case ReferenceType: break; @@ -1728,7 +1728,7 @@ FsmAp *Factor::walk( ParseData *pd ) rtnVal = reItem->walk( pd, 0 ); break; case RegExprType: - rtnVal = regExp->walk( pd, 0 ); + rtnVal = regExpr->walk( pd, 0 ); break; case ReferenceType: rtnVal = varDef->walk( pd ); @@ -1892,7 +1892,7 @@ RegExpr::~RegExpr() { switch ( type ) { case RecurseItem: - delete regExp; + delete regExpr; delete item; break; case Empty: @@ -1911,19 +1911,14 @@ FsmAp *RegExpr::walk( ParseData *pd, RegExpr *rootRegex ) switch ( type ) { case RecurseItem: { /* Walk both items. */ - FsmAp *fsm1 = regExp->walk( pd, rootRegex ); + rtnVal = regExpr->walk( pd, rootRegex ); FsmAp *fsm2 = item->walk( pd, rootRegex ); - if ( fsm1 == 0 ) - rtnVal = fsm2; - else { - fsm1->concatOp( fsm2 ); - rtnVal = fsm1; - } + rtnVal->concatOp( fsm2 ); break; } case Empty: { - /* FIXME: Return something here. */ - rtnVal = 0; + rtnVal = new FsmAp(); + rtnVal->lambdaFsm(); break; } } @@ -1973,6 +1968,10 @@ FsmAp *ReItem::walk( ParseData *pd, RegExpr *rootRegex ) case OrBlock: { /* Get the or block and minmize it. */ rtnVal = orBlock->walk( pd, rootRegex ); + if ( rtnVal == 0 ) { + rtnVal = new FsmAp(); + rtnVal->lambdaFsm(); + } rtnVal->minimizePartition2(); break; } diff --git a/ragel/parsetree.h b/ragel/parsetree.h index a9bcf5c..f208452 100644 --- a/ragel/parsetree.h +++ b/ragel/parsetree.h @@ -557,8 +557,8 @@ struct Factor reItem(reItem), type(OrExprType) { } /* Construct with a regular expression. */ - Factor( RegExpr *regExp ) : - regExp(regExp), type(RegExprType) { } + Factor( RegExpr *regExpr ) : + regExpr(regExpr), type(RegExprType) { } /* Construct with a reference to a var def. */ Factor( const InputLoc &loc, VarDef *varDef ) : @@ -584,7 +584,7 @@ struct Factor Literal *literal; Range *range; ReItem *reItem; - RegExpr *regExp; + RegExpr *regExpr; VarDef *varDef; Join *join; LongestMatch *longestMatch; @@ -628,14 +628,14 @@ struct RegExpr /* Constructors. */ RegExpr() : type(Empty), caseInsensitive(false) { } - RegExpr(RegExpr *regExp, ReItem *item) : - regExp(regExp), item(item), + RegExpr(RegExpr *regExpr, ReItem *item) : + regExpr(regExpr), item(item), type(RecurseItem), caseInsensitive(false) { } ~RegExpr(); FsmAp *walk( ParseData *pd, RegExpr *rootRegex ); - RegExpr *regExp; + RegExpr *regExpr; ReItem *item; RegExpType type; bool caseInsensitive;