From f3aa52c1539a1ea8e9cf620a5a95e7de623f65a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Tue, 8 Mar 2016 16:01:57 +0100 Subject: [PATCH] 2016-03-08 16:01 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbmzip/mzip.c ! fixed memory leak ! typo in comment * contrib/hbziparc/ziparc.prg ! strip leading dir separators from filenames stored in ZIP file when parameter of hb_ZipFile() is not set. --- ChangeLog.txt | 9 +++++++++ contrib/hbmzip/mzip.c | 26 +++++++++----------------- contrib/hbziparc/ziparc.prg | 19 ++++++++++++++----- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6eec5b1686..43a76264b0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,15 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-03-08 16:01 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbmzip/mzip.c + ! fixed memory leak + ! typo in comment + + * contrib/hbziparc/ziparc.prg + ! strip leading dir separators from filenames stored in ZIP file when + parameter of hb_ZipFile() is not set. + 2016-03-08 14:52 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/lang/Makefile + src/lang/l_de_at.c diff --git a/contrib/hbmzip/mzip.c b/contrib/hbmzip/mzip.c index 498ed73f56..2595389aa3 100644 --- a/contrib/hbmzip/mzip.c +++ b/contrib/hbmzip/mzip.c @@ -740,7 +740,7 @@ static HB_BOOL hb_zipGetFileInfo( const char * pszFileName, HB_U32 * pulCRC, HB_ } -/* hb_zipFileCRC32( cFileName ) --> nError */ +/* hb_zipFileCRC32( cFileName ) --> nCRC */ HB_FUNC( HB_ZIPFILECRC32 ) { const char * szFileName = hb_parc( 1 ); @@ -759,8 +759,6 @@ HB_FUNC( HB_ZIPFILECRC32 ) static int hb_zipStoreFile( zipFile hZip, int iParamFileName, int iParamZipName, const char * szPassword, int iParamComment, HB_BOOL fUnicode ) { const char * szFileName = hb_parc( iParamFileName ); - const char * szName = hb_parc( iParamZipName ); - char * pString; PHB_FILE pFile; HB_SIZE nLen; HB_FATTR ulExtAttr; @@ -956,30 +954,23 @@ static int hb_zipStoreFile( zipFile hZip, int iParamFileName, int iParamZipName, szComment = hb_parc( iParamComment ); } - if( szName ) + nLen = strlen( szZipName ); + if( iParamZipName != iParamFileName ) { /* change path separators to '/' */ - nLen = strlen( szZipName ); - pString = szZipName; while( nLen-- ) { - if( pString[ nLen ] == '\\' ) - pString[ nLen ] = '/'; + if( szZipName[ nLen ] == '\\' ) + szZipName[ nLen ] = '/'; } } else { - /* get file name */ - szZipName = hb_strdup( szFileName ); - - nLen = strlen( szZipName ); - pString = szZipName; - while( nLen-- ) { - if( pString[ nLen ] == '/' || pString[ nLen ] == '\\' ) + if( szZipName[ nLen ] == '/' || szZipName[ nLen ] == '\\' ) { - memmove( szZipName, &pString[ nLen + 1 ], strlen( szZipName ) - nLen ); + memmove( szZipName, &szZipName[ nLen + 1 ], strlen( szZipName ) - nLen ); break; } } @@ -1040,7 +1031,8 @@ static int hb_zipStoreFile( zipFile hZip, int iParamFileName, int iParamZipName, szPassword, ulCRC, _version_made_by( fUnicode ), flags ); if( iResult == 0 ) { - pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE ); + char * pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE ); + while( ( nLen = hb_fileRead( pFile, pString, HB_Z_IOBUF_SIZE, -1 ) ) > 0 && nLen != ( HB_SIZE ) FS_ERROR ) zipWriteInFileInZip( hZip, pString, ( unsigned ) nLen ); diff --git a/contrib/hbziparc/ziparc.prg b/contrib/hbziparc/ziparc.prg index c5d55785fc..77d75bca5b 100644 --- a/contrib/hbziparc/ziparc.prg +++ b/contrib/hbziparc/ziparc.prg @@ -298,9 +298,9 @@ FUNCTION hb_ZipFile( ; aProcFile := {} FOR EACH cFN IN hb_defaultValue( acFiles, {} ) hb_FNameSplit( cFN, @cPath, NIL, NIL, @cDrive ) - IF hb_LeftEq( cPath, "." + hb_ps() ) /* strip current dir if any */ + DO WHILE hb_LeftEq( cPath, "." + hb_ps() ) /* strip current dir if any */ cPath := SubStr( cPath, Len( "." + hb_ps() ) + 1 ) - ENDIF + ENDDO IF "?" $ cFN .OR. "*" $ cFN IF lFullPath cPath := hb_PathJoin( hb_cwd(), cPath ) @@ -342,10 +342,19 @@ FUNCTION hb_ZipFile( ; hb_FGetDateTime( cFileToZip, @tTime ) hb_FNameSplit( cFileToZip, @cPath, @cName, @cExt, @cDrive ) - IF ! lWithDrive .AND. ! Empty( cDrive ) .AND. hb_LeftEq( cPath, cDrive + hb_osDriveSeparator() ) - cPath := SubStr( cPath, Len( cDrive + hb_osDriveSeparator() ) + 1 ) + IF lWithPath + IF ! lWithDrive + IF ! Empty( cDrive ) .AND. hb_LeftEq( cPath, cDrive += hb_osDriveSeparator() ) + cPath := SubStr( cPath, Len( cDrive ) + 1 ) + ENDIF + DO WHILE Left( cPath, 1 ) $ "\/" + cPath := SubStr( cPath, 2 ) + ENDDO + ENDIF + ELSE + cPath := NIL ENDIF - hb_zipFileCreate( hZip, StrTran( hb_FNameMerge( iif( lWithPath, cPath, NIL ), cName, cExt ), "\", "/" ), ; + hb_zipFileCreate( hZip, hb_FNameMerge( cPath, cName, cExt ), ; tTime,,,,, nLevel, cPassword, iif( Empty( cPassword ), NIL, hb_zipFileCRC32( cFileToZip ) ), NIL ) DO WHILE ( nLen := FRead( hHandle, @cBuffer, hb_BLen( cBuffer ) ) ) > 0