diff --git a/ChangeLog.txt b/ChangeLog.txt index 89da1a2b87..48d712ac6b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,60 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-01-20 17:36 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rtl/hbsocket.c + * removed not longer valid TODO note + + * contrib/hbmisc/bbabble.c + ! fixed buffer size calculation (it fixes buffer overflow for small + strings, i.e. 2 bytes and does not allocate more memory then necessary + for long ones) + + * contrib/hbct/dattime2.c + ! fixed CToMonth() and CToDoW() to respect case intensive search for + strings with national characters + * variable name synced with Viktor branch + + * contrib/hbct/strswap.c + ! fixed NULL reference when neither 1-st nor 2-nd parameter is passed + by reference + + * contrib/hbct/fcopy.prg + ! fixed source file positioning in case of partial write + ! use hb_FGetDateTime() / hb_FSetDateTime() instead of + FileDate()+FileTime() / SetFDaTi() + It's faster and unlike FileDate() and FileTime() it does + not leave directory open. + ! fixed typo (RTE) + % minor simplification + + * src/rtl/disksphb.c + ! use dynamic binding for GetDiskFreeSpaceEx() function + + ; modifications below comes from Viktor fork: + + * contrib/hbct/ctwin.c + % removed unnecessary declaration + + * contrib/hbct/envparam.c + ! do not call FreeEnvironmentStrings() is it's not necessary + + * contrib/hbodbc/odbc.c + ! fixed potential buffer overflow in SQLERROR()/SQLGETDIAGREC() + + * contrib/hbnetio/netiosrv.c + ! fixed possible NULL reference + + * contrib/hbct/ctnet.c + ! added missing check for result of WinAPI function call + + * contrib/hbct/cttime.prg + ! SecToTime(): fixed regression from 2007-11-18 13:46 UTC+0100 + + * contrib/hbwin/hbolesrv.c + ! fixed char -> TCHAR after recent unicodification + + 2014-01-14 23:36 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * config/win/global.mk * utils/hbmk2/hbmk2.prg diff --git a/contrib/hbct/ctnet.c b/contrib/hbct/ctnet.c index ae9487ce24..3dc6395c6b 100644 --- a/contrib/hbct/ctnet.c +++ b/contrib/hbct/ctnet.c @@ -192,10 +192,13 @@ HB_FUNC( NETRMTNAME ) DWORD dwSize = 0; LPCTSTR lpLocalName = HB_PARSTRDEF( 1, &hLocalDev, NULL ); - WNetGetConnection( lpLocalName, lpRemoteDevice, &dwSize ); - - if( dwSize > 0 && dwSize <= dwLen && WNetGetConnection( lpLocalName, lpRemoteDevice, &dwSize ) == NO_ERROR ) - HB_RETSTRLEN( lpRemoteDevice, ( HB_SIZE ) ( dwSize - 1 ) ); + if( WNetGetConnection( lpLocalName, lpRemoteDevice, &dwSize ) == ERROR_MORE_DATA ) + { + if( dwSize > 0 && dwSize <= dwLen && WNetGetConnection( lpLocalName, lpRemoteDevice, &dwSize ) == NO_ER + HB_RETSTRLEN( lpRemoteDevice, ( HB_SIZE ) ( dwSize - 1 ) ); + else + hb_retc_null(); + } else hb_retc_null(); diff --git a/contrib/hbct/cttime.prg b/contrib/hbct/cttime.prg index cff98c80e3..43b88dd001 100644 --- a/contrib/hbct/cttime.prg +++ b/contrib/hbct/cttime.prg @@ -77,14 +77,14 @@ FUNCTION TimeToSec( cTime ) RETURN Round( nSec, 2 ) /* round FL val to be sure that you can compare it */ -FUNCTION SecToTime( nSec, lHundr ) +FUNCTION SecToTime( nSec, lHundredth ) LOCAL i, h, n n := iif( ! HB_ISNUMERIC( nSec ), Seconds(), nSec ) - IF HB_ISLOGICAL( lHundr ) .AND. lHundr - h := ":" + StrZero( ( nSec * 100 ) % 100, 2 ) + IF HB_ISLOGICAL( lHundredth ) .AND. lHundredth + h := StrZero( ( nSec * 100 ) % 100, 2 ) ELSE h := "" ENDIF @@ -92,7 +92,7 @@ FUNCTION SecToTime( nSec, lHundr ) n := Int( n % 86400 ) FOR i := 1 TO 3 - h := StrZero( n % 60, 2 ) + iif( Len( h ) == 0, "", ":" ) + h + h := StrZero( n % 60, 2 ) + iif( h == "", "", ":" + h ) n := Int( n / 60 ) NEXT diff --git a/contrib/hbct/ctwin.c b/contrib/hbct/ctwin.c index fc0f481054..bbdc3b5823 100644 --- a/contrib/hbct/ctwin.c +++ b/contrib/hbct/ctwin.c @@ -2291,7 +2291,7 @@ static int hb_ctw_gt_Alert( PHB_GT pGT, PHB_ITEM pMessage, PHB_ITEM pOptions, PHB_CODEPAGE cdp = hb_vmCDP(); for( i = 1; i <= iOptions; ++i ) { - HB_SIZE nOptLen = hb_arrayGetCLen( pOptions, i ); + nOptLen = hb_arrayGetCLen( pOptions, i ); if( nOptLen > 0 ) { HB_SIZE nIdx1 = 0, nIdx2 = 0; diff --git a/contrib/hbct/dattime2.c b/contrib/hbct/dattime2.c index af9caa0e86..83e777aa85 100644 --- a/contrib/hbct/dattime2.c +++ b/contrib/hbct/dattime2.c @@ -83,10 +83,10 @@ static int ct_daysinmonth( int iMonth, HB_BOOL bLeap ) static int ct_daystomonth( int iMonth, HB_BOOL bLeap ) { - static const int iMonthes[] = { + static const int sc_iMonthes[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - return ( iMonth < 1 && iMonth > 12 ) ? 0 : iMonthes[ iMonth - 1 ] + + return ( iMonth < 1 && iMonth > 12 ) ? 0 : sc_iMonthes[ iMonth - 1 ] + ( ( bLeap && iMonth > 2 ) ? 1 : 0 ); } @@ -107,12 +107,13 @@ HB_FUNC( CTODOW ) if( nLen ) { + PHB_CODEPAGE cdp = hb_vmCDP(); const char * szParam = hb_parc( 1 ); for( iDow = 7; iDow > 0; iDow-- ) { const char * szDow = hb_langDGetItem( HB_LANG_ITEM_BASE_DAY + iDow - 1 ); - if( hb_strnicmp( szDow, szParam, nLen ) == 0 ) + if( hb_cdpicmp( szDow, strlen( szDow ), szParam, nLen, cdp, HB_FALSE ) == 0 ) break; } } @@ -127,11 +128,12 @@ HB_FUNC( CTOMONTH ) if( nLen ) { + PHB_CODEPAGE cdp = hb_vmCDP(); const char * szParam = hb_parc( 1 ); for( iMonth = 12; iMonth > 0; iMonth-- ) { const char * szMonth = hb_langDGetItem( HB_LANG_ITEM_BASE_MONTH + iMonth - 1 ); - if( hb_strnicmp( szMonth, szParam, nLen ) == 0 ) + if( hb_cdpicmp( szMonth, strlen( szMonth ), szParam, nLen, cdp, HB_FALSE ) == 0 ) break; } } diff --git a/contrib/hbct/envparam.c b/contrib/hbct/envparam.c index e2f5a9522e..99857539bf 100644 --- a/contrib/hbct/envparam.c +++ b/contrib/hbct/envparam.c @@ -131,9 +131,9 @@ HB_FUNC( ENVPARAM ) *lpDst++ = '\n'; } } - } - FreeEnvironmentStrings( lpEnviron ); + FreeEnvironmentStrings( lpEnviron ); + } if( lpResult ) { diff --git a/contrib/hbct/fcopy.prg b/contrib/hbct/fcopy.prg index 07067e99c8..0076ca992c 100644 --- a/contrib/hbct/fcopy.prg +++ b/contrib/hbct/fcopy.prg @@ -67,7 +67,6 @@ THREAD STATIC t_hSrcFile := F_ERROR THREAD STATIC t_lSetDaTi := .T. -THREAD STATIC t_fileDate THREAD STATIC t_fileTime /* @@ -92,7 +91,7 @@ FUNCTION FileCopy( cSource, cDest, lMode ) IF t_hSrcFile != F_ERROR hDstFile := FCreate( cDest ) IF hDstFile != F_ERROR - DO WHILE ! lDone + DO WHILE .T. nSrcBytes := FRead( t_hSrcFile, @cBuffer, F_BLOCK ) IF nSrcBytes == 0 lDone := .T. @@ -103,6 +102,9 @@ FUNCTION FileCopy( cSource, cDest, lMode ) nTotBytes += nDstBytes ENDIF IF nDstBytes < nSrcBytes + IF lMode + FSeek( t_hSrcFile, nDstBytes - nSrcBytes, FS_RELATIVE ) + ENDIF EXIT ENDIF ENDDO @@ -111,10 +113,9 @@ FUNCTION FileCopy( cSource, cDest, lMode ) FClose( t_hSrcFile ) t_hSrcFile := F_ERROR ENDIF - t_fileDate := FileDate( cSource ) - t_fileTime := FileTime( cSource ) - IF t_lSetDaTi - SetFDaTi( cDest, t_fileDate, t_fileTime ) + hb_FGetDateTime( cSource, @t_fileTime ) + IF t_lSetDaTi .and. !Empty( t_fileTime ) + hb_FSetDateTime( cDest, t_fileTime ) ENDIF ELSE FClose( t_hSrcFile ) @@ -148,10 +149,10 @@ FUNCTION FileCCont( cDest ) IF t_hSrcFile != F_ERROR hDstFile := FCreate( cDest ) IF hDstFile != F_ERROR - DO WHILE ! lDone + DO WHILE .T. nSrcBytes := FRead( t_hSrcFile, @cBuffer, F_BLOCK ) IF nSrcBytes == 0 - lDone := 0 + lDone := .T. EXIT ENDIF nDstBytes := FWrite( hDstFile, cBuffer, nSrcBytes ) @@ -167,8 +168,8 @@ FUNCTION FileCCont( cDest ) FClose( t_hSrcFile ) t_hSrcFile := F_ERROR ENDIF - IF t_lSetDaTi - SetFDaTi( cDest, t_fileDate, t_fileTime ) + IF t_lSetDaTi .and. !Empty( t_fileTime ) + hb_FSetDateTime( cDest, t_fileTime ) ENDIF ENDIF ENDIF diff --git a/contrib/hbct/strswap.c b/contrib/hbct/strswap.c index a78ad04068..7dd36ddc53 100644 --- a/contrib/hbct/strswap.c +++ b/contrib/hbct/strswap.c @@ -89,7 +89,7 @@ HB_FUNC( STRSWAP ) if( iChange2 ) *( pcRet2 + sIndex ) = cExchange; } - else + else if( iChange2 ) *( pcRet2 + sIndex ) = *( pcString1 + sIndex ); } diff --git a/contrib/hbmisc/bbabble.c b/contrib/hbmisc/bbabble.c index 9ea98316c1..f14ad6eb50 100644 --- a/contrib/hbmisc/bbabble.c +++ b/contrib/hbmisc/bbabble.c @@ -62,7 +62,7 @@ HB_FUNC( BUBBLEBABBLEENCODE ) const char * pszInput = hb_parcx( 1 ); HB_ISIZ nInputLen = hb_parclen( 1 ); - char * pszResult = ( char * ) hb_xgrab( ( nInputLen * 4 ) + 1 ); + char * pszResult = ( char * ) hb_xgrab( nInputLen * 3 + 6 ); HB_ISIZ nPos = 0; HB_ISIZ i; @@ -103,7 +103,6 @@ HB_FUNC( BUBBLEBABBLEENCODE ) } pszResult[ nPos++ ] = 'x'; - pszResult[ nPos ] = '\0'; - hb_retc_buffer( pszResult ); + hb_retclen_buffer( pszResult, nPos ); } diff --git a/contrib/hbnetio/netiosrv.c b/contrib/hbnetio/netiosrv.c index 888792bb14..5426b75bfe 100644 --- a/contrib/hbnetio/netiosrv.c +++ b/contrib/hbnetio/netiosrv.c @@ -746,9 +746,11 @@ static HB_BOOL s_netio_login_accept( PHB_CONSRV conn ) } if( ! conn->login ) s_consrv_disconnect( conn ); + + return conn->login; } - return conn->login; + return HB_FALSE; } /* netio_VerifyClient( ) -> diff --git a/contrib/hbodbc/odbc.c b/contrib/hbodbc/odbc.c index 847f082d70..0e80048ca0 100644 --- a/contrib/hbodbc/odbc.c +++ b/contrib/hbodbc/odbc.c @@ -796,7 +796,7 @@ HB_FUNC( SQLERROR ) /* hEnv, hDbc, hStmt, @cErrorClass, @nType, @cErrorMsg */ ( SQLTCHAR * ) buffer, ( SQLINTEGER * ) &lError, ( SQLTCHAR * ) szErrorMsg, - ( SQLSMALLINT ) sizeof( szErrorMsg ), + ( SQLSMALLINT ) HB_SIZEOFARRAY( szErrorMsg ), ( SQLSMALLINT * ) &iLen ) ); O_HB_STORSTR( ( O_HB_CHAR * ) buffer, 4 ); @@ -845,7 +845,7 @@ HB_FUNC( SQLGETDIAGREC ) /* nHandleType, hHandle, nRecNumber, @cSQLState, @nErro ( SQLTCHAR * ) szSQLState, ( SQLINTEGER * ) &lError, ( SQLTCHAR * ) szErrorMsg, - ( SQLSMALLINT ) sizeof( szErrorMsg ), + ( SQLSMALLINT ) HB_SIZEOFARRAY( szErrorMsg ), ( SQLSMALLINT * ) &iLen ) ); O_HB_STORSTR( ( O_HB_CHAR * ) szSQLState, 4 ); diff --git a/contrib/hbwin/hbolesrv.c b/contrib/hbwin/hbolesrv.c index d21b8ed38c..58cb5d87f1 100644 --- a/contrib/hbwin/hbolesrv.c +++ b/contrib/hbwin/hbolesrv.c @@ -153,7 +153,7 @@ static HB_BOOL s_getKeyValue( LPCTSTR lpKey, LPTSTR lpBuffer, int iLen ) iPos = 0; for( ;; ) { - char c = lpKey[ iPos++ ]; + TCHAR c = lpKey[ iPos++ ]; if( c == TEXT( '$' ) || c == TEXT( '@' ) || c == TEXT( '\0' ) ) { if( --iPos ) diff --git a/src/rtl/disksphb.c b/src/rtl/disksphb.c index 622350b614..77d28c97e0 100644 --- a/src/rtl/disksphb.c +++ b/src/rtl/disksphb.c @@ -190,10 +190,17 @@ HB_FUNC( HB_DISKSPACE ) ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; +#if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) + fResult = s_pGetDiskFreeSpaceEx( lpPath, + ( PULARGE_INTEGER ) &i64FreeBytesToCaller, + ( PULARGE_INTEGER ) &i64TotalBytes, + ( PULARGE_INTEGER ) &i64FreeBytes ); +#else fResult = GetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); +#endif hb_fsSetIOError( fResult, 0 ); if( fResult ) diff --git a/src/rtl/hbsocket.c b/src/rtl/hbsocket.c index 1f55023c53..d71fcaddd8 100644 --- a/src/rtl/hbsocket.c +++ b/src/rtl/hbsocket.c @@ -3512,13 +3512,6 @@ PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases ) &pIfInfo->iiBroadcastAddress, sizeof( pIfInfo->iiBroadcastAddress ) ); - /* TODO: - * use GetAdaptersInfo() and bind interafcaes by - * printf("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String); - * - * hb_arraySetC( pItem, HB_SOCKET_IFINFO_HWADDR, hwaddr ); - */ - flags = ( ( flags & IFF_UP ) ? HB_SOCKET_IFF_UP : 0 ) | ( ( flags & IFF_BROADCAST ) ?