From 83bf2ee7d870ca8c676d160f8fede8ddba49deb4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 11 Apr 2012 16:46:54 +0000 Subject: [PATCH] 2012-04-11 18:46 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/src/pp/ppcore.c ! fixed GPF if #pragma __*streaminclude is used with redirect user custom files --- harbour/ChangeLog | 5 +++++ harbour/src/pp/ppcore.c | 32 +++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 33cb14b824..a5082e4de3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,11 @@ The license applies to all entries newer than 2009-04-28. */ +2012-04-11 18:46 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/src/pp/ppcore.c + ! fixed GPF if #pragma __*streaminclude is used with + redirect user custom files + 2012-04-11 13:53 UTC+0200 Viktor Szakats (harbour syenar.net) * utils/hbmk2/hbmk2.prg * do not consider ".C" (uppercase c) as C++ source file. diff --git a/harbour/src/pp/ppcore.c b/harbour/src/pp/ppcore.c index 7e784b239a..5f780c678f 100644 --- a/harbour/src/pp/ppcore.c +++ b/harbour/src/pp/ppcore.c @@ -2214,9 +2214,14 @@ static void hb_pp_pragmaStreamFile( PHB_PP_STATE pState, const char * szFileName { HB_SIZE nSize; - (void) fseek( pFile->file_in, 0L, SEEK_END ); - nSize = ftell( pFile->file_in ); - (void) fseek( pFile->file_in, 0L, SEEK_SET ); + if( pFile->file_in ) + { + (void) fseek( pFile->file_in, 0L, SEEK_END ); + nSize = ftell( pFile->file_in ); + (void) fseek( pFile->file_in, 0L, SEEK_SET ); + } + else + nSize = pFile->nLineBufLen; if( nSize > MAX_STREAM_SIZE ) hb_pp_error( pState, 'F', HB_PP_ERR_FILE_TOO_LONG, szFileName ); @@ -2230,14 +2235,23 @@ static void hb_pp_pragmaStreamFile( PHB_PP_STATE pState, const char * szFileName if( nSize ) { - char * pBuffer = ( char * ) hb_xgrab( nSize * sizeof( char ) ); + if( pFile->file_in == NULL && pState->iStreamDump != HB_PP_STREAM_C ) + hb_membufAddData( pState->pStreamBuffer, pFile->pLineBuf, nSize ); + else + { + char * pBuffer = ( char * ) hb_xgrab( nSize * sizeof( char ) ); - nSize = ( HB_SIZE ) fread( pBuffer, sizeof( char ), nSize, pFile->file_in ); - if( pState->iStreamDump == HB_PP_STREAM_C ) - hb_strRemEscSeq( pBuffer, &nSize ); + if( pFile->file_in ) + nSize = ( HB_SIZE ) fread( pBuffer, sizeof( char ), nSize, pFile->file_in ); + else + memcpy( pBuffer, pFile->pLineBuf, nSize ); - hb_membufAddData( pState->pStreamBuffer, pBuffer, nSize ); - hb_xfree( pBuffer ); + if( pState->iStreamDump == HB_PP_STREAM_C ) + hb_strRemEscSeq( pBuffer, &nSize ); + + hb_membufAddData( pState->pStreamBuffer, pBuffer, nSize ); + hb_xfree( pBuffer ); + } } /* insert new tokens into incoming buffer