diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 085eb17314..d5d9718fce 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,17 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-03 17:23 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbw32/w32_regc.c + ! fixed typo hb_free() => hb_xfree() + ! fixed UNICODE build + + * harbour/source/vm/itemapi.c + * changed hb_itemPutC() and hb_itemPutCL() to be safe when + user call it passing string which is stored in item passed + as first parameter. It should fix problem located by Chen. + Please test. + 2008-06-03 15:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/extrap.c ! fixed unregistering exception error handler in OS2 builds diff --git a/harbour/contrib/hbw32/w32_regc.c b/harbour/contrib/hbw32/w32_regc.c index c0c1cb7be8..8febbdbf0a 100644 --- a/harbour/contrib/hbw32/w32_regc.c +++ b/harbour/contrib/hbw32/w32_regc.c @@ -86,19 +86,20 @@ static HKEY hb_regkeyconv( ULONG nKey ) return Result; } -HB_FUNC( WIN32_REGCREATEKEYEX ) +HB_FUNC( WIN32_REGCREATEKEYEX ) { HKEY hWnd = ( HKEY ) hb_parnl( 8 ); ULONG nResult = hb_parnl( 9 ); - - if( RegCreateKeyEx( hb_regkeyconv( hb_parnl( 1 ) ), - ( const char * ) hb_parc( 2 ), - 0, - NULL, - hb_parnl( 5 ), - hb_parnl( 6 ), - NULL, - &hWnd, + LPTSTR lpText = HB_TCHAR_CONVTO( hb_parc( 2 ) ); + + if( RegCreateKeyEx( hb_regkeyconv( hb_parnl( 1 ) ), + lpText, + 0, + NULL, + hb_parnl( 5 ), + hb_parnl( 6 ), + NULL, + &hWnd, &nResult ) == ERROR_SUCCESS ) { hb_stornl( ( ULONG ) hWnd, 8 ); @@ -108,16 +109,19 @@ HB_FUNC( WIN32_REGCREATEKEYEX ) } else hb_retnl( -1 ); + + HB_TCHAR_FREE( lpText ); } HB_FUNC( WIN32_REGOPENKEYEX ) { HKEY hWnd; + LPTSTR lpText = HB_TCHAR_CONVTO( hb_parc( 2 ) ); - if( RegOpenKeyEx( hb_regkeyconv( hb_parnl( 1 ) ), - hb_parc( 2 ), - 0, - hb_parnl( 4 ), + if( RegOpenKeyEx( hb_regkeyconv( hb_parnl( 1 ) ), + lpText, + 0, + hb_parnl( 4 ), &hWnd ) == ERROR_SUCCESS ) { hb_stornl( ( ULONG ) hWnd, 5 ); @@ -125,67 +129,72 @@ HB_FUNC( WIN32_REGOPENKEYEX ) } else hb_retnl( -1 ); + + HB_TCHAR_FREE( lpText ); } HB_FUNC( WIN32_REGQUERYVALUEEX ) { - const char * cKey = ( const char * ) hb_parc( 2 ) ; DWORD nType = 0; DWORD nSize = 0; - - if( RegQueryValueEx( hb_regkeyconv( hb_parnl( 1 ) ), - cKey, - NULL, - &nType, - NULL, + LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parc( 2 ) ); + + if( RegQueryValueEx( hb_regkeyconv( hb_parnl( 1 ) ), + lpKey, + NULL, + &nType, + NULL, &nSize ) == ERROR_SUCCESS ) { if( nSize > 0 ) { BYTE * cValue = ( BYTE * ) hb_xgrab( nSize + 1 ); - RegQueryValueEx( hb_regkeyconv( hb_parnl( 1 ) ), - cKey, - NULL, - &nType, - ( BYTE * ) cValue, + RegQueryValueEx( hb_regkeyconv( hb_parnl( 1 ) ), + lpKey, + NULL, + &nType, + ( BYTE * ) cValue, &nSize ); hb_stornl( nType, 4 ); if( ! hb_storclen_buffer( ( char * ) cValue, nSize, 5 ) ) - hb_free( cValue ); + hb_xfree( cValue ); } } + HB_TCHAR_FREE( lpKey ); hb_retnl( nSize ); } HB_FUNC( WIN32_REGSETVALUEEX ) { - const char * cKey = hb_parc( 2 ); DWORD nType = hb_parnl( 4 ); - + LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parc( 2 ) ); + if( nType != REG_DWORD ) { BYTE * cValue = ( BYTE * ) hb_parc( 5 ); - hb_retni( RegSetValueEx( hb_regkeyconv( hb_parnl( 1 ) ), - cKey, - 0, - nType, - ( BYTE * ) cValue, + hb_retni( RegSetValueEx( hb_regkeyconv( hb_parnl( 1 ) ), + lpKey, + 0, + nType, + ( BYTE * ) cValue, hb_parclen( 5 ) + 1 ) ); } else { DWORD nSpace = hb_parnl( 5 ); - hb_retni( RegSetValueEx( hb_regkeyconv( hb_parnl( 1 ) ), - cKey, - 0, - nType, - ( BYTE * ) &nSpace, + hb_retni( RegSetValueEx( hb_regkeyconv( hb_parnl( 1 ) ), + lpKey, + 0, + nType, + ( BYTE * ) &nSpace, sizeof( REG_DWORD ) ) ); } + + HB_TCHAR_FREE( lpKey ); } HB_FUNC( WIN32_REGCLOSEKEY ) diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index 8d5501bc22..a6b9c5cf73 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -215,10 +215,22 @@ HB_EXPORT PHB_ITEM hb_itemArrayPut( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pIt HB_EXPORT PHB_ITEM hb_itemPutC( PHB_ITEM pItem, const char * szText ) { - ULONG ulLen = szText ? strlen( szText ) : 0; + ULONG ulLen, ulAlloc; HB_TRACE(HB_TR_DEBUG, ("hb_itemPutC(%p, %s)", pItem, szText)); + ulLen = szText ? strlen( szText ) : 0; + if( ulLen > 1 ) + { + ulAlloc = ulLen + 1; + szText = ( char * ) hb_xmemcpy( hb_xgrab( ulAlloc ), szText, ulAlloc ); + } + else + { + ulAlloc = 0; + szText = ( char * ) ( ulLen ? hb_szAscii[ ( unsigned char ) ( szText[0] ) ] : "" ); + } + if( pItem ) { if( HB_IS_COMPLEX( pItem ) ) @@ -227,36 +239,32 @@ HB_EXPORT PHB_ITEM hb_itemPutC( PHB_ITEM pItem, const char * szText ) else pItem = hb_itemNew( NULL ); - if( ulLen == 0 ) - { - pItem->item.asString.value = ""; - pItem->item.asString.length = 0; - pItem->item.asString.allocated = 0; - } - else if( ulLen == 1 ) - { - pItem->item.asString.value = ( char * ) hb_szAscii[ (unsigned char) ( szText[0] ) ]; - pItem->item.asString.length = 1; - pItem->item.asString.allocated = 0; - } - else - { - pItem->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); - /* we used strlen() above so we know it's 0-ended string */ - hb_xmemcpy( pItem->item.asString.value, szText, ulLen + 1 ); - pItem->item.asString.length = ulLen; - pItem->item.asString.allocated = ulLen + 1; - } - pItem->type = HB_IT_STRING; + pItem->item.asString.value = ( char * ) szText; + pItem->item.asString.length = ulLen; + pItem->item.asString.allocated = ulAlloc; return pItem; } HB_EXPORT PHB_ITEM hb_itemPutCL( PHB_ITEM pItem, const char * szText, ULONG ulLen ) { + ULONG ulAlloc; + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCL(%p, %s, %lu)", pItem, szText, ulLen)); + if( ulLen > 1 ) + { + ulAlloc = ulLen + 1; + szText = ( char * ) hb_xmemcpy( hb_xgrab( ulAlloc ), szText, ulLen ); + ( ( char * ) szText )[ ulLen ] = '\0'; + } + else + { + ulAlloc = 0; + szText = ( char * ) ( ulLen ? hb_szAscii[ ( unsigned char ) ( szText[0] ) ] : "" ); + } + if( pItem ) { if( HB_IS_COMPLEX( pItem ) ) @@ -269,28 +277,10 @@ HB_EXPORT PHB_ITEM hb_itemPutCL( PHB_ITEM pItem, const char * szText, ULONG ulLe trash if the szText buffer is NULL, at least with hb_retclen(). [vszakats] */ - if( szText == NULL || ulLen == 0 ) - { - pItem->item.asString.value = ""; - pItem->item.asString.length = 0; - pItem->item.asString.allocated = 0; - } - else if( ulLen == 1 ) - { - pItem->item.asString.value = ( char * ) hb_szAscii[ (unsigned char) ( szText[0] ) ]; - pItem->item.asString.length = 1; - pItem->item.asString.allocated = 0; - } - else - { - pItem->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); - hb_xmemcpy( pItem->item.asString.value, szText, ulLen ); - pItem->item.asString.value[ ulLen ] = '\0'; - pItem->item.asString.length = ulLen; - pItem->item.asString.allocated = ulLen + 1; - } - pItem->type = HB_IT_STRING; + pItem->item.asString.value = ( char * ) szText; + pItem->item.asString.length = ulLen; + pItem->item.asString.allocated = ulAlloc; return pItem; } @@ -336,9 +326,6 @@ HB_EXPORT PHB_ITEM hb_itemPutCLConst( PHB_ITEM pItem, const char * szText, ULONG else pItem = hb_itemNew( NULL ); - pItem->type = HB_IT_STRING; - pItem->item.asString.allocated = 0; - if( szText == NULL ) { pItem->item.asString.value = ""; @@ -353,6 +340,9 @@ HB_EXPORT PHB_ITEM hb_itemPutCLConst( PHB_ITEM pItem, const char * szText, ULONG pItem->item.asString.length = ulLen; } + pItem->type = HB_IT_STRING; + pItem->item.asString.allocated = 0; + return pItem; }