From 56cb6bcd62d4e44a7c793f1f06775b83762e1d00 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sun, 14 Jan 2007 15:09:30 +0000 Subject: [PATCH] 2007-01-14 16:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/macro/macro.y * formatting * harbour/source/vm/macro.c ! fixed macrocompiler for proper compilation of string with embedded ASCII NUL byte (chr(0)), f.e.: ? &("'["+chr(0)+"]'") --- harbour/ChangeLog | 8 ++++++++ harbour/source/macro/macro.y | 4 ++-- harbour/source/vm/macro.c | 32 +++++++++++++++++++------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3bd282a850..b5532013f6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,14 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-01-14 16:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/macro/macro.y + * formatting + * harbour/source/vm/macro.c + ! fixed macrocompiler for proper compilation of string with embedded + ASCII NUL byte (chr(0)), f.e.: + ? &("'["+chr(0)+"]'") + 2007-01-13 14:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/rdd_ads/adsfunc.c * harbour/source/rdd/workarea.c diff --git a/harbour/source/macro/macro.y b/harbour/source/macro/macro.y index defaabcf60..f2117e305e 100644 --- a/harbour/source/macro/macro.y +++ b/harbour/source/macro/macro.y @@ -235,7 +235,7 @@ static void hb_macroIdentNew( HB_COMP_DECL, char * ); %% -Main : Expression '\n' { +Main : Expression '\n' { HB_MACRO_DATA->exprType = hb_compExprType( $1 ); if( HB_MACRO_DATA->Flags & HB_MACRO_GEN_PUSH ) hb_compExprGenPush( $1, HB_COMP_PARAM ); @@ -244,7 +244,7 @@ Main : Expression '\n' { hb_compGenPCode1( HB_P_ENDPROC, HB_COMP_PARAM ); } - | Expression { + | Expression { HB_MACRO_DATA->exprType = hb_compExprType( $1 ); if( HB_MACRO_DATA->Flags & HB_MACRO_GEN_PUSH ) hb_compExprGenPush( $1, HB_COMP_PARAM ); diff --git a/harbour/source/vm/macro.c b/harbour/source/vm/macro.c index 980451f837..04acc66015 100644 --- a/harbour/source/vm/macro.c +++ b/harbour/source/vm/macro.c @@ -76,14 +76,14 @@ static ULONG s_macroFlags = HB_SM_SHORTCUTS; * 'iFlag' - specifies if compiled code should generate pcodes either for push * operation (for example: var :=¯o) or for pop operation (¯o :=var) */ -static int hb_macroParse( HB_MACRO_PTR pMacro, char * szString ) +static int hb_macroParse( HB_MACRO_PTR pMacro, char * szString, ULONG ulLen ) { /* initialize the input buffer - it will be scanned by lex */ pMacro->string = szString; - pMacro->length = strlen( szString ); + pMacro->length = ulLen; pMacro->pError = NULL; - HB_TRACE(HB_TR_DEBUG, ("hb_macroParse(%p, %s)", pMacro, szString)); + HB_TRACE(HB_TR_DEBUG, ("hb_macroParse(%p, %s, %lu)", pMacro, szString, ulLen)); /* initialize the output (pcode) buffer - it will be filled by yacc */ pMacro->pCodeInfo = (HB_PCODE_INFO_PTR ) hb_xgrab( sizeof( HB_PCODE_INFO ) ); @@ -92,7 +92,6 @@ static int hb_macroParse( HB_MACRO_PTR pMacro, char * szString ) pMacro->pCodeInfo->fVParams = FALSE; pMacro->pCodeInfo->pLocals = NULL; pMacro->pCodeInfo->pPrev = NULL; - HB_TRACE(HB_TR_DEBUG, ("hb_macroParse.(%p, %s)", pMacro, szString)); pMacro->pCodeInfo->pCode = ( BYTE * ) hb_xgrab( HB_PCODE_SIZE ); /* reset the type of compiled expression - this should be filled after @@ -416,6 +415,7 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext, BYTE flags ) HB_MACRO struMacro; int iStatus; char * szString = pItem->item.asString.value; + ULONG ulLen = pItem->item.asString.length; #ifdef HB_MACRO_STATEMENTS char * pText; char * pOut; @@ -471,10 +471,11 @@ void hb_macroGetValue( HB_ITEM_PTR pItem, BYTE iContext, BYTE flags ) hb_pp_ParseExpression( ptr, pOut ); szString = pText; + ulLen = strlen( pText ); } #endif - iStatus = hb_macroParse( &struMacro, szString ); + iStatus = hb_macroParse( &struMacro, szString, ulLen ); #ifdef HB_MACRO_STATEMENTS if( struMacro.supported & HB_SM_PREPROC ) { @@ -510,6 +511,7 @@ void hb_macroSetValue( HB_ITEM_PTR pItem, BYTE flags ) if( hb_macroCheckParam( pItem ) ) { char * szString = pItem->item.asString.value; + ULONG ulLen = pItem->item.asString.length; HB_MACRO struMacro; int iStatus; @@ -518,7 +520,7 @@ void hb_macroSetValue( HB_ITEM_PTR pItem, BYTE flags ) struMacro.Flags = HB_MACRO_GEN_POP; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; - iStatus = hb_macroParse( &struMacro, szString ); + iStatus = hb_macroParse( &struMacro, szString, ulLen ); hb_stackPop(); /* remove compiled string */ if( iStatus == HB_MACRO_OK && ( struMacro.status & HB_MACRO_CONT ) ) @@ -550,7 +552,8 @@ static void hb_macroUseAliased( HB_ITEM_PTR pAlias, HB_ITEM_PTR pVar, int iFlag, { /* grab memory for "alias->var" */ - char * szString = ( char * ) hb_xgrab( pAlias->item.asString.length + pVar->item.asString.length + 3 ); + ULONG ulLen = pAlias->item.asString.length + pVar->item.asString.length + 2; + char * szString = ( char * ) hb_xgrab( ulLen + 1 ); HB_MACRO struMacro; int iStatus; @@ -558,14 +561,14 @@ static void hb_macroUseAliased( HB_ITEM_PTR pAlias, HB_ITEM_PTR pVar, int iFlag, szString[ pAlias->item.asString.length ] = '-'; szString[ pAlias->item.asString.length + 1 ] = '>'; memcpy( szString + pAlias->item.asString.length + 2, pVar->item.asString.value, pVar->item.asString.length ); - szString[ pAlias->item.asString.length + 2 + pVar->item.asString.length ] = '\0'; + szString[ ulLen ] = '\0'; struMacro.mode = HB_MODE_MACRO; struMacro.supported = (bSupported & HB_SM_RT_MACRO) ? s_macroFlags : bSupported; struMacro.Flags = iFlag; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; - iStatus = hb_macroParse( &struMacro, szString ); + iStatus = hb_macroParse( &struMacro, szString, ulLen ); hb_xfree( szString ); struMacro.string = NULL; @@ -587,13 +590,14 @@ static void hb_macroUseAliased( HB_ITEM_PTR pAlias, HB_ITEM_PTR pVar, int iFlag, HB_MACRO struMacro; int iStatus; char * szString = pVar->item.asString.value; + ULONG ulLen = pVar->item.asString.length; struMacro.mode = HB_MODE_MACRO; struMacro.supported = (bSupported & HB_SM_RT_MACRO) ? s_macroFlags : bSupported; struMacro.Flags = iFlag | HB_MACRO_GEN_ALIASED; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; - iStatus = hb_macroParse( &struMacro, szString ); + iStatus = hb_macroParse( &struMacro, szString, ulLen ); hb_stackPop(); /* remove compiled string */ @@ -662,11 +666,12 @@ HB_MACRO_PTR hb_macroCompile( char * szString ) pMacro = ( HB_MACRO_PTR ) hb_xgrab( sizeof( HB_MACRO ) ); pMacro->mode = HB_MODE_MACRO; pMacro->supported = s_macroFlags; - pMacro->Flags = HB_MACRO_DEALLOCATE | HB_MACRO_GEN_PUSH; + pMacro->Flags = HB_MACRO_DEALLOCATE | HB_MACRO_GEN_PUSH | + HB_MACRO_GEN_LIST | HB_MACRO_GEN_PARE; pMacro->uiNameLen = HB_SYMBOL_NAME_LEN; pMacro->status = HB_MACRO_CONT; - iStatus = hb_macroParse( pMacro, szString ); + iStatus = hb_macroParse( pMacro, szString, strlen( szString ) ); if( ! ( iStatus == HB_MACRO_OK && ( pMacro->status & HB_MACRO_CONT ) ) ) { hb_macroDelete( pMacro ); @@ -757,13 +762,14 @@ char * hb_macroGetType( HB_ITEM_PTR pItem ) HB_MACRO struMacro; int iStatus; char * szString = pItem->item.asString.value; + ULONG ulLen = pItem->item.asString.length; struMacro.mode = HB_MODE_MACRO; struMacro.supported = s_macroFlags; struMacro.Flags = HB_MACRO_GEN_PUSH | HB_MACRO_GEN_TYPE; struMacro.uiNameLen = HB_SYMBOL_NAME_LEN; struMacro.status = HB_MACRO_CONT; - iStatus = hb_macroParse( &struMacro, szString ); + iStatus = hb_macroParse( &struMacro, szString, ulLen ); if( iStatus == HB_MACRO_OK ) {