From f3a3469af02fa9a50a1da198099da3f7ebb19d9a Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 24 Nov 2008 15:40:18 +0000 Subject: [PATCH] 2008-11-24 16:41 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/pp/ppcore.c * harbour/source/rtl/run.c * harbour/source/rtl/errorint.c * harbour/source/rtl/trace.c * harbour/contrib/xhb/hboutdbg.c * pacified warnings and updated some possibly danger constructions * harbour/source/vm/memvars.c % improved the performance of __MVRESTORE() ; TOFIX: this code has Clipper incompatible extension which may cause that incorrect values will be restored - numeric double values with 0 as default number of decimal places for str() formatting are wrongly converted to integers loosing fractional part of number. --- harbour/ChangeLog | 15 +++++++++++++ harbour/contrib/xhb/hboutdbg.c | 13 +++++++++-- harbour/source/pp/ppcore.c | 29 ++++++++++++++++++------ harbour/source/rtl/errorint.c | 4 ++-- harbour/source/rtl/run.c | 2 +- harbour/source/rtl/trace.c | 2 +- harbour/source/vm/memvars.c | 41 +++++++++++++++++++++------------- 7 files changed, 78 insertions(+), 28 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4a3da43670..2afc1ca787 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,21 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-11-24 16:41 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/pp/ppcore.c + * harbour/source/rtl/run.c + * harbour/source/rtl/errorint.c + * harbour/source/rtl/trace.c + * harbour/contrib/xhb/hboutdbg.c + * pacified warnings and updated some possibly danger constructions + + * harbour/source/vm/memvars.c + % improved the performance of __MVRESTORE() + ; TOFIX: this code has Clipper incompatible extension which may cause + that incorrect values will be restored - numeric double values with + 0 as default number of decimal places for str() formatting are + wrongly converted to integers loosing fractional part of number. + 2008-11-24 12:34 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hberrors.h * harbour/source/compiler/hbgenerr.c diff --git a/harbour/contrib/xhb/hboutdbg.c b/harbour/contrib/xhb/hboutdbg.c index b4cc91f8d3..021fbf48cd 100644 --- a/harbour/contrib/xhb/hboutdbg.c +++ b/harbour/contrib/xhb/hboutdbg.c @@ -204,8 +204,17 @@ void hb_OutDebug( const char * szMsg, ULONG ulMsgLen ) if( select( s_iDebugFd + 1, NULL, &wrds, NULL, &tv ) > 0 ) { - write( s_iDebugFd, szMsg, ulMsgLen ); - write( s_iDebugFd, "\n", 1 ); + if( ( ULONG ) write( s_iDebugFd, szMsg, ulMsgLen ) == ulMsgLen ) + { + tv.tv_sec = 0; + tv.tv_usec = 100000; + FD_ZERO(&wrds); + FD_SET(s_iDebugFd, &wrds); + if( select( s_iDebugFd + 1, NULL, &wrds, NULL, &tv ) > 0 ) + { + if( write( s_iDebugFd, "\n", 1 ) != 1 ) {} + } + } } } } diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 820f152aed..ce5bc436f5 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -100,6 +100,7 @@ #define HB_PP_ERR_NESTED_INCLUDES 31 /* C3009 */ #define HB_PP_ERR_INVALID_DIRECTIVE 32 /* C3010 */ #define HB_PP_ERR_CANNOT_OPEN_RULES 33 /* C3011 */ +#define HB_PP_ERR_WRITE_FILE 34 /* C3029 */ /* warning messages */ @@ -148,6 +149,7 @@ static const char * hb_pp_szErrors[] = "Too many nested #includes", /* C3009 */ "Invalid name follows #", /* C3010 */ "Can't open standard rule file '%s'" /* C3011 */ + "Write error to intermediate file '%s'" /* C3029 */ }; @@ -837,7 +839,8 @@ static void hb_pp_dumpEnd( PHB_PP_STATE pState ) pBuffer = hb_membufPtr( pState->pDumpBuffer ); ulLen = hb_membufLen( pState->pDumpBuffer ); fputs( "#pragma BEGINDUMP\n", pState->file_out ); - ( void ) fwrite( pBuffer, sizeof( char ), ulLen, pState->file_out ); + if( fwrite( pBuffer, sizeof( char ), ulLen, pState->file_out ) != ulLen ) + hb_pp_error( pState, 'F', HB_PP_ERR_WRITE_FILE, pState->szOutFileName ); fputs( "#pragma ENDDUMP\n", pState->file_out ); while( ulLen-- ) @@ -2516,8 +2519,12 @@ static void hb_pp_pragmaNew( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) hb_membufAddCh( pState->pBuffer, '\n' ); if( pState->fWriteTrace ) { - ( void ) fwrite( hb_membufPtr( pState->pBuffer ), sizeof( char ), - hb_membufLen( pState->pBuffer ), pState->file_trace ); + if( fwrite( hb_membufPtr( pState->pBuffer ), sizeof( char ), + hb_membufLen( pState->pBuffer ), pState->file_out ) != + hb_membufLen( pState->pBuffer ) ) + { + hb_pp_error( pState, 'F', HB_PP_ERR_WRITE_FILE, pState->szTraceFileName ); + } } if( pState->fTracePragmas ) { @@ -5124,8 +5131,12 @@ PHB_PP_TOKEN hb_pp_tokenGet( PHB_PP_STATE pState ) pState->usLastType ); #endif pState->usLastType = HB_PP_TOKEN_TYPE( pState->pTokenOut->type ); - ( void ) fwrite( hb_membufPtr( pState->pBuffer ), sizeof( char ), - hb_membufLen( pState->pBuffer ), pState->file_out ); + if( fwrite( hb_membufPtr( pState->pBuffer ), sizeof( char ), + hb_membufLen( pState->pBuffer ), pState->file_out ) != + hb_membufLen( pState->pBuffer ) ) + { + hb_pp_error( pState, 'F', HB_PP_ERR_WRITE_FILE, pState->szOutFileName ); + } } return pState->pTokenOut; @@ -5873,8 +5884,12 @@ void hb_pp_tokenToString( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) { if( !fError ) hb_membufAddCh( pState->pBuffer, ']' ); - ( void ) fwrite( hb_membufPtr( pState->pBuffer ), sizeof( char ), - hb_membufLen( pState->pBuffer ), pState->file_out ); + if( fwrite( hb_membufPtr( pState->pBuffer ), sizeof( char ), + hb_membufLen( pState->pBuffer ), pState->file_out ) != + hb_membufLen( pState->pBuffer ) ) + { + hb_pp_error( pState, 'F', HB_PP_ERR_WRITE_FILE, pState->szOutFileName ); + } } } diff --git a/harbour/source/rtl/errorint.c b/harbour/source/rtl/errorint.c index d2b48b0021..77a5a68c09 100644 --- a/harbour/source/rtl/errorint.c +++ b/harbour/source/rtl/errorint.c @@ -107,7 +107,7 @@ void hb_errInternalRaw( ULONG ulIntCode, const char * szText, const char * szPar hb_conOutErr( buffer, 0 ); if( hLog ) - ( void ) fwrite( buffer, sizeof( buffer[ 0 ] ), strlen( buffer ), hLog ); + fprintf( hLog, "%s", buffer ); if( szText ) hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); @@ -130,7 +130,7 @@ void hb_errInternalRaw( ULONG ulIntCode, const char * szText, const char * szPar hb_conOutErr( msg, 0 ); if( hLog ) - ( void ) fwrite( msg, sizeof( msg[ 0 ] ), strlen( msg ), hLog ); + fprintf( hLog, "%s", msg ); } if( hLog ) diff --git a/harbour/source/rtl/run.c b/harbour/source/rtl/run.c index 703d6b80ae..96524b9a70 100644 --- a/harbour/source/rtl/run.c +++ b/harbour/source/rtl/run.c @@ -61,7 +61,7 @@ HB_FUNC( __RUN ) { if( ISCHAR( 1 ) && hb_gtSuspend() == 0 ) { - ( void ) system( hb_parc( 1 ) ); + if( system( hb_parc( 1 ) ) != 0 ) {} if( hb_gtResume() != 0 ) { diff --git a/harbour/source/rtl/trace.c b/harbour/source/rtl/trace.c index 66a98d0bb6..921b520b68 100644 --- a/harbour/source/rtl/trace.c +++ b/harbour/source/rtl/trace.c @@ -68,6 +68,6 @@ HB_FUNC( HB_TRACESTRING ) char * szMessage = hb_parc( 1 ); if( szMessage ) { - HB_TRACE(HB_TR_ALWAYS, (szMessage) ); + HB_TRACE(HB_TR_ALWAYS, ("%s", szMessage) ); } } diff --git a/harbour/source/vm/memvars.c b/harbour/source/vm/memvars.c index dd36837c49..9f7f8c81cc 100644 --- a/harbour/source/vm/memvars.c +++ b/harbour/source/vm/memvars.c @@ -1509,6 +1509,8 @@ HB_FUNC( __MVRESTORE ) BOOL bIncludeMask; BYTE buffer[ HB_MEM_REC_LEN ]; const char * pszMask; + char *szName; + PHB_ITEM pItem = NULL; #ifdef HB_C52_STRICT pszMask = "*"; @@ -1520,11 +1522,13 @@ HB_FUNC( __MVRESTORE ) while( hb_fsRead( fhnd, buffer, HB_MEM_REC_LEN ) == HB_MEM_REC_LEN ) { - char *szName = hb_strdup( ( char * ) buffer ); USHORT uiType = ( USHORT ) ( buffer[ 11 ] - 128 ); USHORT uiWidth = ( USHORT ) buffer[ 16 ]; USHORT uiDec = ( USHORT ) buffer[ 17 ]; - PHB_ITEM pItem = NULL; + + /* protect against corrupted files */ + buffer[ 10 ] = '\0'; + szName = ( char * ) buffer; switch( uiType ) { @@ -1536,9 +1540,12 @@ HB_FUNC( __MVRESTORE ) pbyString = ( BYTE * ) hb_xgrab( uiWidth ); if( hb_fsRead( fhnd, pbyString, uiWidth ) == uiWidth ) - pItem = hb_itemPutCL( NULL, ( char * ) pbyString, uiWidth - 1 ); - - hb_xfree( pbyString ); + pItem = hb_itemPutCLPtr( pItem, ( char * ) pbyString, uiWidth - 1 ); + else + { + hb_xfree( pbyString ); + szName = NULL; + } break; } @@ -1548,7 +1555,9 @@ HB_FUNC( __MVRESTORE ) BYTE pbyNumber[ HB_MEM_NUM_LEN ]; if( hb_fsRead( fhnd, pbyNumber, HB_MEM_NUM_LEN ) == HB_MEM_NUM_LEN ) - pItem = hb_itemPutNLen( NULL, HB_GET_LE_DOUBLE( pbyNumber ), uiWidth - ( uiDec ? ( uiDec + 1 ) : 0 ), uiDec ); + pItem = hb_itemPutNLen( pItem, HB_GET_LE_DOUBLE( pbyNumber ), uiWidth - ( uiDec ? ( uiDec + 1 ) : 0 ), uiDec ); + else + szName = NULL; break; } @@ -1558,7 +1567,9 @@ HB_FUNC( __MVRESTORE ) BYTE pbyNumber[ HB_MEM_NUM_LEN ]; if( hb_fsRead( fhnd, pbyNumber, HB_MEM_NUM_LEN ) == HB_MEM_NUM_LEN ) - pItem = hb_itemPutDL( NULL, ( long ) HB_GET_LE_DOUBLE( pbyNumber ) ); + pItem = hb_itemPutDL( pItem, ( long ) HB_GET_LE_DOUBLE( pbyNumber ) ); + else + szName = NULL; break; } @@ -1568,13 +1579,18 @@ HB_FUNC( __MVRESTORE ) BYTE pbyLogical[ 1 ]; if( hb_fsRead( fhnd, pbyLogical, 1 ) == 1 ) - pItem = hb_itemPutL( NULL, pbyLogical[ 0 ] != 0 ); + pItem = hb_itemPutL( pItem, pbyLogical[ 0 ] != 0 ); + else + szName = NULL; break; } + + default: + szName = NULL; } - if( pItem ) + if( szName ) { BOOL bMatch = hb_strMatchCaseWildExact( szName, pszMask ); @@ -1590,18 +1606,13 @@ HB_FUNC( __MVRESTORE ) else /* attempt to assign a value to undeclared variable create the PRIVATE one */ hb_memvarCreateFromDynSymbol( hb_dynsymGet( szName ), VS_PRIVATE, pItem ); - - hb_itemReturn( pItem ); } - - hb_itemRelease( pItem ); } - - hb_xfree( szName ); } hb_fsClose( fhnd ); hb_memvarUpdatePrivatesBase(); + hb_itemReturnRelease( pItem ); } else hb_retl( FALSE );