diff options
88 files changed, 967 insertions, 748 deletions
diff --git a/C/7zArcIn.c b/C/7zArcIn.c index ca2d5f6e..2beed3d5 100644 --- a/C/7zArcIn.c +++ b/C/7zArcIn.c @@ -1,5 +1,5 @@ /* 7zArcIn.c -- 7z Input functions -2016-03-31 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -1100,13 +1100,11 @@ static SRes SzReadHeader2( ISzAlloc *allocTemp ) { - UInt64 type; - UInt32 numFiles = 0; - UInt32 numEmptyStreams = 0; CSubStreamInfo ssi; - const Byte *emptyStreams = NULL; - const Byte *emptyFiles = NULL; +{ + UInt64 type; + SzData_Clear(&ssi.sdSizes); SzData_Clear(&ssi.sdCRCs); SzData_Clear(&ssi.sdNumSubStreams); @@ -1120,9 +1118,9 @@ static SRes SzReadHeader2( { for (;;) { - UInt64 type; - RINOK(ReadID(sd, &type)); - if (type == k7zIdEnd) + UInt64 type2; + RINOK(ReadID(sd, &type2)); + if (type2 == k7zIdEnd) break; RINOK(SkipData(sd)); } @@ -1160,6 +1158,13 @@ static SRes SzReadHeader2( if (type != k7zIdFilesInfo) return SZ_ERROR_ARCHIVE; +} + +{ + UInt32 numFiles = 0; + UInt32 numEmptyStreams = 0; + const Byte *emptyStreams = NULL; + const Byte *emptyFiles = NULL; RINOK(SzReadNumber32(sd, &numFiles)); p->NumFiles = numFiles; @@ -1458,7 +1463,7 @@ static SRes SzReadHeader2( if (ssi.sdNumSubStreams.Data && ssi.sdNumSubStreams.Size != 0) return SZ_ERROR_ARCHIVE; } - +} return SZ_OK; } diff --git a/C/7zVersion.h b/C/7zVersion.h index d4c60367..9faf5a4e 100644 --- a/C/7zVersion.h +++ b/C/7zVersion.h @@ -1,9 +1,9 @@ #define MY_VER_MAJOR 16 -#define MY_VER_MINOR 00 +#define MY_VER_MINOR 01 #define MY_VER_BUILD 0 -#define MY_VERSION_NUMBERS "16.00" -#define MY_VERSION "16.00" -#define MY_DATE "2016-05-10" +#define MY_VERSION_NUMBERS "16.01" +#define MY_VERSION "16.01" +#define MY_DATE "2016-05-19" #undef MY_COPYRIGHT #undef MY_VERSION_COPYRIGHT_DATE #define MY_AUTHOR_NAME "Igor Pavlov" diff --git a/C/HuffEnc.c b/C/HuffEnc.c index db41e8d2..55b497e5 100644 --- a/C/HuffEnc.c +++ b/C/HuffEnc.c @@ -1,5 +1,5 @@ /* HuffEnc.c -- functions for Huffman encoding -2009-09-02 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -121,8 +121,8 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb i = 0; for (len = maxLen; len != 0; len--) { - UInt32 num; - for (num = lenCounters[len]; num != 0; num--) + UInt32 k; + for (k = lenCounters[len]; k != 0; k--) lens[p[i++] & MASK] = (Byte)len; } } @@ -138,9 +138,9 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */ { - UInt32 i; - for (i = 0; i < numSymbols; i++) - p[i] = nextCodes[lens[i]]++; + UInt32 k; + for (k = 0; k < numSymbols; k++) + p[k] = nextCodes[lens[k]]++; } } } diff --git a/C/Lzma86Dec.c b/C/Lzma86Dec.c index 7d89b2fc..21031745 100644 --- a/C/Lzma86Dec.c +++ b/C/Lzma86Dec.c @@ -1,5 +1,5 @@ /* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder -2015-11-08 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -9,9 +9,6 @@ #include "Bra.h" #include "LzmaDec.h" -static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); } -static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); } - SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize) { unsigned i; @@ -25,7 +22,6 @@ SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize) SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen) { - ISzAlloc g_Alloc = { SzAlloc, SzFree }; SRes res; int useFilter; SizeT inSizePure; diff --git a/C/Lzma86Enc.c b/C/Lzma86Enc.c index bfb7727d..a15b58d6 100644 --- a/C/Lzma86Enc.c +++ b/C/Lzma86Enc.c @@ -1,5 +1,5 @@ /* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder -2015-11-08 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -13,13 +13,9 @@ #define SZE_OUT_OVERFLOW SZE_DATA_ERROR -static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); } -static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); } - int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, int level, UInt32 dictSize, int filterMode) { - ISzAlloc g_Alloc = { SzAlloc, SzFree }; size_t outSize2 = *destLen; Byte *filteredStream; Bool useFilter; diff --git a/C/LzmaDec.c b/C/LzmaDec.c index 27efbaba..12dce11f 100644 --- a/C/LzmaDec.c +++ b/C/LzmaDec.c @@ -1,5 +1,5 @@ /* LzmaDec.c -- LZMA Decoder -2015-06-23 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -294,14 +294,14 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte #ifdef _LZMA_SIZE_OPT { - unsigned limit, offset; + unsigned lim, offset; CLzmaProb *probLen = prob + LenChoice; IF_BIT_0(probLen) { UPDATE_0(probLen); probLen = prob + LenLow + (posState << kLenNumLowBits); offset = 0; - limit = (1 << kLenNumLowBits); + lim = (1 << kLenNumLowBits); } else { @@ -312,17 +312,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte UPDATE_0(probLen); probLen = prob + LenMid + (posState << kLenNumMidBits); offset = kLenNumLowSymbols; - limit = (1 << kLenNumMidBits); + lim = (1 << kLenNumMidBits); } else { UPDATE_1(probLen); probLen = prob + LenHigh; offset = kLenNumLowSymbols + kLenNumMidSymbols; - limit = (1 << kLenNumHighBits); + lim = (1 << kLenNumHighBits); } } - TREE_DECODE(probLen, limit, len); + TREE_DECODE(probLen, lim, len); len += offset; } #else diff --git a/C/LzmaEnc.c b/C/LzmaEnc.c index 9c164e6f..70df4569 100644 --- a/C/LzmaEnc.c +++ b/C/LzmaEnc.c @@ -1,5 +1,5 @@ /* LzmaEnc.c -- LZMA Encoder -2015-11-08 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -108,7 +108,7 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2) #define kDicLogSizeMaxCompress 32 -#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); } +#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); } static UInt32 GetPosSlot1(UInt32 pos) { @@ -145,19 +145,19 @@ static void LzmaEnc_FastPosInit(Byte *g_FastPos) /* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */ /* -#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \ +#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \ (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \ - res = p->g_FastPos[pos >> i] + (i * 2); } + res = p->g_FastPos[pos >> zz] + (zz * 2); } */ /* -#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \ +#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \ (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \ - res = p->g_FastPos[pos >> i] + (i * 2); } + res = p->g_FastPos[pos >> zz] + (zz * 2); } */ -#define BSR2_RET(pos, res) { UInt32 i = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \ - res = p->g_FastPos[pos >> i] + (i * 2); } +#define BSR2_RET(pos, res) { UInt32 zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \ + res = p->g_FastPos[pos >> zz] + (zz * 2); } /* #define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \ @@ -983,12 +983,17 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) { - UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur; - UInt32 matchPrice, repMatchPrice, normalMatchPrice; + UInt32 lenEnd, cur; UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS]; UInt32 *matches; + + { + + UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, len; + UInt32 matchPrice, repMatchPrice, normalMatchPrice; const Byte *data; Byte curByte, matchByte; + if (p->optimumEndIndex != p->optimumCurrentIndex) { const COptimal *opt = &p->opt[p->optimumCurrentIndex]; @@ -1176,8 +1181,11 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } #endif + } + for (;;) { + UInt32 numAvail; UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen; UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice; Bool nextIsChar; @@ -1465,6 +1473,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) for (lenTest = /*2*/ startLen; ; lenTest++) { UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN]; + { UInt32 lenToPosState = GetLenToPosState(lenTest); COptimal *opt; if (curBack < kNumFullDistances) @@ -1480,6 +1489,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) opt->backPrev = curBack + LZMA_NUM_REPS; opt->prev1IsChar = False; } + } if (/*_maxMode && */lenTest == matches[offs]) { @@ -1509,15 +1519,15 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) /* for (; lenTest2 >= 2; lenTest2--) */ { UInt32 offset = cur + lenTest + 1 + lenTest2; - UInt32 curAndLenPrice; + UInt32 curAndLenPrice2; COptimal *opt; while (lenEnd < offset) p->opt[++lenEnd].price = kInfinityPrice; - curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); + curAndLenPrice2 = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); opt = &p->opt[offset]; - if (curAndLenPrice < opt->price) + if (curAndLenPrice2 < opt->price) { - opt->price = curAndLenPrice; + opt->price = curAndLenPrice2; opt->posPrev = cur + lenTest + 1; opt->backPrev = 0; opt->prev1IsChar = True; @@ -1718,7 +1728,6 @@ static void FillDistancesPrices(CLzmaEnc *p) { UInt32 *distancesPrices = p->distancesPrices[lenToPosState]; - UInt32 i; for (i = 0; i < kStartPosModelIndex; i++) distancesPrices[i] = posSlotPrices[i]; for (; i < kNumFullDistances; i++) @@ -1,5 +1,5 @@ /* Ppmd.h -- PPMD codec common code -2013-01-18 : Igor Pavlov : Public domain +2016-05-16 : Igor Pavlov : Public domain This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ #ifndef __PPMD_H @@ -77,8 +77,8 @@ typedef CPpmd_Byte_Ref; #define PPMD_SetAllBitsIn256Bytes(p) \ - { unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \ - p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }} + { unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \ + p[z+7] = p[z+6] = p[z+5] = p[z+4] = p[z+3] = p[z+2] = p[z+1] = p[z+0] = ~(size_t)0; }} EXTERN_C_END @@ -1,5 +1,5 @@ /* Ppmd8.c -- PPMdI codec -2015-09-28 : Igor Pavlov : Public domain +2016-05-16 : Igor Pavlov : Public domain This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */ #include "Precomp.h" @@ -240,8 +240,8 @@ static void *AllocUnits(CPpmd8 *p, unsigned indx) } #define MyMem12Cpy(dest, src, num) \ - { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \ - do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while (--n); } + { UInt32 *d = (UInt32 *)dest; const UInt32 *z = (const UInt32 *)src; UInt32 n = num; \ + do { d[0] = z[0]; d[1] = z[1]; d[2] = z[2]; z += 3; d += 3; } while (--n); } static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU) { @@ -772,7 +772,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) if (SUCCESSOR(s) <= upBranch) { CTX_PTR successor; - CPpmd_State *s1 = p->FoundState; + CPpmd_State *s2 = p->FoundState; p->FoundState = s; successor = CreateSuccessors(p, False, NULL, c); @@ -780,7 +780,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) SetSuccessor(s, 0); else SetSuccessor(s, REF(successor)); - p->FoundState = s1; + p->FoundState = s2; } if (p->OrderFall == 1 && c1 == p->MaxContext) @@ -924,19 +924,19 @@ static void UpdateModel(CPpmd8 *p) } else { - CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0); - if (!s) + CPpmd_State *s2 = (CPpmd_State*)AllocUnits(p, 0); + if (!s2) { RESTORE_MODEL(c, CTX(fSuccessor)); return; } - *s = *ONE_STATE(c); - c->Stats = REF(s); - if (s->Freq < MAX_FREQ / 4 - 1) - s->Freq <<= 1; + *s2 = *ONE_STATE(c); + c->Stats = REF(s2); + if (s2->Freq < MAX_FREQ / 4 - 1) + s2->Freq <<= 1; else - s->Freq = MAX_FREQ - 4; - c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 2)); + s2->Freq = MAX_FREQ - 4; + c->SummFreq = (UInt16)(s2->Freq + p->InitEsc + (ns > 2)); } cf = 2 * fFreq * (c->SummFreq + 6); sf = (UInt32)s0 + c->SummFreq; @@ -951,10 +951,10 @@ static void UpdateModel(CPpmd8 *p) c->SummFreq = (UInt16)(c->SummFreq + cf); } { - CPpmd_State *s = STATS(c) + ns1 + 1; - SetSuccessor(s, successor); - s->Symbol = fSymbol; - s->Freq = (Byte)cf; + CPpmd_State *s2 = STATS(c) + ns1 + 1; + SetSuccessor(s2, successor); + s2->Symbol = fSymbol; + s2->Freq = (Byte)cf; c->Flags |= flag; c->NumStats = (Byte)(ns1 + 1); } diff --git a/C/Util/7z/7zMain.c b/C/Util/7z/7zMain.c index ed6bab2a..1837e9d6 100644 --- a/C/Util/7z/7zMain.c +++ b/C/Util/7z/7zMain.c @@ -1,5 +1,5 @@ /* 7zMain.c - Test application for 7z Decoder -2015-08-02 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -310,10 +310,10 @@ static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s) ms[1] = 29; for (mon = 0;; mon++) { - unsigned s = ms[mon]; - if (v < s) + unsigned d = ms[mon]; + if (v < d) break; - v -= s; + v -= d; } s = UIntToStr(s, year, 4); *s++ = '-'; UIntToStr_2(s, mon + 1); s[2] = '-'; s += 3; diff --git a/C/Util/7zipUninstall/7zipUninstall.c b/C/Util/7zipUninstall/7zipUninstall.c index cd66002a..cdbc2d5e 100644 --- a/C/Util/7zipUninstall/7zipUninstall.c +++ b/C/Util/7zipUninstall/7zipUninstall.c @@ -1,5 +1,5 @@ /* 7zipUninstall.c - 7-Zip Uninstaller -2015-12-26 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -362,9 +362,11 @@ static void WriteCLSID() { if (AreEqual_Path_PrefixName(s, path, L"7-zip.dll")) { - LONG res = MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc); - if (res == ERROR_SUCCESS) - MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip); + { + LONG res = MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc); + if (res == ERROR_SUCCESS) + MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip); + } { unsigned i; @@ -397,9 +399,11 @@ static void WriteCLSID() { if (AreEqual_Path_PrefixName(s, path, L"7-zip32.dll")) { - LONG res = MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc); - if (res == ERROR_SUCCESS) - MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip); + { + LONG res = MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc); + if (res == ERROR_SUCCESS) + MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip); + } { unsigned i; diff --git a/C/Util/SfxSetup/SfxSetup.c b/C/Util/SfxSetup/SfxSetup.c index 0e5152e5..4bb82e7c 100644 --- a/C/Util/SfxSetup/SfxSetup.c +++ b/C/Util/SfxSetup/SfxSetup.c @@ -1,5 +1,5 @@ /* SfxSetup.c - 7z SFX Setup -2015-11-08 : Igor Pavlov : Public domain */ +2016-05-16 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -396,11 +396,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, { size_t offset = 0; size_t outSizeProcessed = 0; - size_t len; WCHAR *temp; - len = SzArEx_GetFileNameUtf16(&db, i, NULL); - - if (len >= MAX_PATH) + + if (SzArEx_GetFileNameUtf16(&db, i, NULL) >= MAX_PATH) { res = SZ_ERROR_FAIL; break; diff --git a/CPP/7zip/Archive/7z/7zDecode.cpp b/CPP/7zip/Archive/7z/7zDecode.cpp index bfe1b24e..b0d6dd83 100644 --- a/CPP/7zip/Archive/7z/7zDecode.cpp +++ b/CPP/7zip/Archive/7z/7zDecode.cpp @@ -404,11 +404,11 @@ HRESULT CDecoder::Decode( len = password.Len(); } CByteBuffer buffer(len * 2); - for (size_t i = 0; i < len; i++) + for (size_t k = 0; k < len; k++) { - wchar_t c = passwordBSTR[i]; - ((Byte *)buffer)[i * 2] = (Byte)c; - ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8); + wchar_t c = passwordBSTR[k]; + ((Byte *)buffer)[k * 2] = (Byte)c; + ((Byte *)buffer)[k * 2 + 1] = (Byte)(c >> 8); } RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, (UInt32)buffer.Size())); } diff --git a/CPP/7zip/Archive/7z/7zEncode.cpp b/CPP/7zip/Archive/7z/7zEncode.cpp index ab251711..97e9ad7a 100644 --- a/CPP/7zip/Archive/7z/7zEncode.cpp +++ b/CPP/7zip/Archive/7z/7zEncode.cpp @@ -148,9 +148,9 @@ HRESULT CEncoder::CreateMixerCoder( RINOK(_mixer->SetBindInfo(_bindInfo)); - FOR_VECTOR (i, _options.Methods) + FOR_VECTOR (m, _options.Methods) { - const CMethodFull &methodFull = _options.Methods[i]; + const CMethodFull &methodFull = _options.Methods[m]; CCreatedCoder cod; @@ -410,9 +410,9 @@ HRESULT CEncoder::Encode( mtOutStreamNotifySpec->_stream = outStream; mtOutStreamNotifySpec->_mtProgresSpec = mtProgressSpec; - FOR_VECTOR(i, tempBufferSpecs) + FOR_VECTOR(t, tempBufferSpecs) { - tempBufferSpecs[i]->_mtProgresSpec = mtProgressSpec; + tempBufferSpecs[t]->_mtProgresSpec = mtProgressSpec; } } @@ -591,9 +591,9 @@ HRESULT CEncoder::EncoderConstr() continue; } - int i = _bindInfo.FindStream_in_PackStreams(outIndex); - if (i >= 0) - _bindInfo.PackStreams.MoveToFront(i); + int si = _bindInfo.FindStream_in_PackStreams(outIndex); + if (si >= 0) + _bindInfo.PackStreams.MoveToFront(si); break; } } diff --git a/CPP/7zip/Archive/7z/7zExtract.cpp b/CPP/7zip/Archive/7z/7zExtract.cpp index 83965164..05fd80de 100644 --- a/CPP/7zip/Archive/7z/7zExtract.cpp +++ b/CPP/7zip/Archive/7z/7zExtract.cpp @@ -319,13 +319,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, curUnpacked += _db.Files[k].Size; } - HRESULT result = folderOutStream->Init(fileIndex, - allFilesMode ? NULL : indices + i, - numSolidFiles); + { + HRESULT result = folderOutStream->Init(fileIndex, + allFilesMode ? NULL : indices + i, + numSolidFiles); - i += numSolidFiles; + i += numSolidFiles; - RINOK(result); + RINOK(result); + } // to test solid block with zero unpacked size we disable that code if (folderOutStream->WasWritingFinished()) diff --git a/CPP/7zip/Archive/7z/7zHandler.cpp b/CPP/7zip/Archive/7z/7zHandler.cpp index a95fc6a0..ccd2c624 100644 --- a/CPP/7zip/Archive/7z/7zHandler.cpp +++ b/CPP/7zip/Archive/7z/7zHandler.cpp @@ -429,11 +429,11 @@ HRESULT CHandler::SetMethodToProp(CNum folderIndex, PROPVARIANT *prop) const name = "LZMA2"; if (propsSize == 1) { - Byte p = props[0]; - if ((p & 1) == 0) - ConvertUInt32ToString((UInt32)((p >> 1) + 12), s); + Byte d = props[0]; + if ((d & 1) == 0) + ConvertUInt32ToString((UInt32)((d >> 1) + 12), s); else - GetStringForSizeValue(s, 3 << ((p >> 1) + 11)); + GetStringForSizeValue(s, 3 << ((d >> 1) + 11)); } } else if (id == k_PPMD) diff --git a/CPP/7zip/Archive/7z/7zHandlerOut.cpp b/CPP/7zip/Archive/7z/7zHandlerOut.cpp index 41bd6520..2b86ed26 100644 --- a/CPP/7zip/Archive/7z/7zHandlerOut.cpp +++ b/CPP/7zip/Archive/7z/7zHandlerOut.cpp @@ -675,14 +675,16 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt static HRESULT ParseBond(UString &srcString, UInt32 &coder, UInt32 &stream) { stream = 0; - int index = ParseStringToUInt32(srcString, coder); - if (index == 0) - return E_INVALIDARG; - srcString.DeleteFrontal(index); + { + unsigned index = ParseStringToUInt32(srcString, coder); + if (index == 0) + return E_INVALIDARG; + srcString.DeleteFrontal(index); + } if (srcString[0] == 's') { srcString.Delete(0); - int index = ParseStringToUInt32(srcString, stream); + unsigned index = ParseStringToUInt32(srcString, stream); if (index == 0) return E_INVALIDARG; srcString.DeleteFrontal(index); diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp index 0634768b..b0c6b98c 100644 --- a/CPP/7zip/Archive/7z/7zIn.cpp +++ b/CPP/7zip/Archive/7z/7zIn.cpp @@ -1150,9 +1150,8 @@ HRESULT CInArchive::ReadHeader( if (type == NID::kFilesInfo) { - CNum numFiles = ReadNum(); + const CNum numFiles = ReadNum(); db.Files.ClearAndSetSize(numFiles); - CNum i; /* db.Files.Reserve(numFiles); CNum i; @@ -1174,8 +1173,8 @@ HRESULT CInArchive::ReadHeader( for (;;) { - UInt64 type = ReadID(); - if (type == NID::kEnd) + const UInt64 type2 = ReadID(); + if (type2 == NID::kEnd) break; UInt64 size = ReadNumber(); if (size > _inByteBack->GetRem()) @@ -1184,9 +1183,9 @@ HRESULT CInArchive::ReadHeader( switchProp.Set(this, _inByteBack->GetPtr(), (size_t)size, true); bool addPropIdToList = true; bool isKnownType = true; - if (type > ((UInt32)1 << 30)) + if (type2 > ((UInt32)1 << 30)) isKnownType = false; - else switch ((UInt32)type) + else switch ((UInt32)type2) { case NID::kName: { @@ -1220,7 +1219,7 @@ HRESULT CInArchive::ReadHeader( ReadBoolVector2(db.Files.Size(), boolVector); CStreamSwitch streamSwitch; streamSwitch.Set(this, &dataVector); - for (i = 0; i < numFiles; i++) + for (CNum i = 0; i < numFiles; i++) { CFileItem &file = db.Files[i]; file.AttribDefined = boolVector[i]; @@ -1263,7 +1262,7 @@ HRESULT CInArchive::ReadHeader( { ReadBoolVector(numFiles, emptyStreamVector); numEmptyStreams = 0; - for (i = 0; i < (CNum)emptyStreamVector.Size(); i++) + for (CNum i = 0; i < (CNum)emptyStreamVector.Size(); i++) if (emptyStreamVector[i]) numEmptyStreams++; @@ -1337,7 +1336,7 @@ HRESULT CInArchive::ReadHeader( if (isKnownType) { if (addPropIdToList) - db.ArcInfo.FileInfoPopIDs.Add(type); + db.ArcInfo.FileInfoPopIDs.Add(type2); } else { @@ -1358,6 +1357,9 @@ HRESULT CInArchive::ReadHeader( CNum sizeIndex = 0; CNum numAntiItems = 0; + + CNum i; + for (i = 0; i < numEmptyStreams; i++) if (antiFileVector[i]) numAntiItems++; diff --git a/CPP/7zip/Archive/7z/7zOut.cpp b/CPP/7zip/Archive/7z/7zOut.cpp index 2f906588..3e70f466 100644 --- a/CPP/7zip/Archive/7z/7zOut.cpp +++ b/CPP/7zip/Archive/7z/7zOut.cpp @@ -540,13 +540,13 @@ void COutArchive::WriteHeader( */ _useAlign = true; - unsigned i; - - UInt64 packedSize = 0; - for (i = 0; i < db.PackSizes.Size(); i++) - packedSize += db.PackSizes[i]; + { + UInt64 packSize = 0; + FOR_VECTOR (i, db.PackSizes) + packSize += db.PackSizes[i]; + headerOffset = packSize; + } - headerOffset = packedSize; WriteByte(NID::kHeader); @@ -560,7 +560,7 @@ void COutArchive::WriteHeader( CRecordVector<UInt64> unpackSizes; CUInt32DefVector digests; - for (i = 0; i < db.Files.Size(); i++) + FOR_VECTOR (i, db.Files) { const CFileItem &file = db.Files[i]; if (!file.HasStream) @@ -588,14 +588,17 @@ void COutArchive::WriteHeader( CBoolVector emptyStreamVector; emptyStreamVector.ClearAndSetSize(db.Files.Size()); unsigned numEmptyStreams = 0; - for (i = 0; i < db.Files.Size(); i++) - if (db.Files[i].HasStream) - emptyStreamVector[i] = false; - else - { - emptyStreamVector[i] = true; - numEmptyStreams++; - } + { + FOR_VECTOR (i, db.Files) + if (db.Files[i].HasStream) + emptyStreamVector[i] = false; + else + { + emptyStreamVector[i] = true; + numEmptyStreams++; + } + } + if (numEmptyStreams != 0) { WritePropBoolVector(NID::kEmptyStream, emptyStreamVector); @@ -605,7 +608,8 @@ void COutArchive::WriteHeader( antiVector.ClearAndSetSize(numEmptyStreams); bool thereAreEmptyFiles = false, thereAreAntiItems = false; unsigned cur = 0; - for (i = 0; i < db.Files.Size(); i++) + + FOR_VECTOR (i, db.Files) { const CFileItem &file = db.Files[i]; if (file.HasStream) @@ -672,17 +676,21 @@ void COutArchive::WriteHeader( CBoolVector boolVector; boolVector.ClearAndSetSize(db.Files.Size()); unsigned numDefined = 0; - for (i = 0; i < db.Files.Size(); i++) + { - bool defined = db.Files[i].AttribDefined; - boolVector[i] = defined; - if (defined) - numDefined++; + FOR_VECTOR (i, db.Files) + { + bool defined = db.Files[i].AttribDefined; + boolVector[i] = defined; + if (defined) + numDefined++; + } } + if (numDefined != 0) { WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttrib, 4); - for (i = 0; i < db.Files.Size(); i++) + FOR_VECTOR (i, db.Files) { const CFileItem &file = db.Files[i]; if (file.AttribDefined) diff --git a/CPP/7zip/Archive/7z/7zUpdate.cpp b/CPP/7zip/Archive/7z/7zUpdate.cpp index e1c7aad8..4e74fa33 100644 --- a/CPP/7zip/Archive/7z/7zUpdate.cpp +++ b/CPP/7zip/Archive/7z/7zUpdate.cpp @@ -1681,17 +1681,18 @@ HRESULT Update( } UInt64 inSizeForReduce = 0; - unsigned i; - for (i = 0; i < updateItems.Size(); i++) { - const CUpdateItem &ui = updateItems[i]; - if (ui.NewData) + FOR_VECTOR (i, updateItems) { - complexity += ui.Size; - if (numSolidFiles != 1) - inSizeForReduce += ui.Size; - else if (inSizeForReduce < ui.Size) - inSizeForReduce = ui.Size; + const CUpdateItem &ui = updateItems[i]; + if (ui.NewData) + { + complexity += ui.Size; + if (numSolidFiles != 1) + inSizeForReduce += ui.Size; + else if (inSizeForReduce < ui.Size) + inSizeForReduce = ui.Size; + } } } @@ -1753,7 +1754,7 @@ HRESULT Update( const CCompressionMethodMode &method = *options.Method; - for (i = 0; i < updateItems.Size(); i++) + FOR_VECTOR (i, updateItems) { const CUpdateItem &ui = updateItems[i]; if (!ui.NewData || !ui.HasStream()) @@ -1857,6 +1858,8 @@ HRESULT Update( /* ---------- Write non-AUX dirs and Empty files ---------- */ CUIntVector emptyRefs; + unsigned i; + for (i = 0; i < updateItems.Size(); i++) { const CUpdateItem &ui = updateItems[i]; @@ -1919,7 +1922,8 @@ HRESULT Update( const CFilterMode2 &filterMode = filters[groupIndex]; CCompressionMethodMode method = *options.Method; - HRESULT res = MakeExeMethod(method, filterMode, + { + HRESULT res = MakeExeMethod(method, filterMode, #ifdef _7ZIP_ST false #else @@ -1927,7 +1931,8 @@ HRESULT Update( #endif ); - RINOK(res); + RINOK(res); + } if (filterMode.Encrypted) { @@ -2266,8 +2271,12 @@ HRESULT Update( CRecordVector<CRefItem> refItems; refItems.ClearAndSetSize(numFiles); bool sortByType = (options.UseTypeSorting && numSolidFiles > 1); + + unsigned i; + for (i = 0; i < numFiles; i++) refItems[i] = CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType); + CSortParam sortParam; // sortParam.TreeFolders = &treeFolders; sortParam.SortByType = sortByType; diff --git a/CPP/7zip/Archive/ArHandler.cpp b/CPP/7zip/Archive/ArHandler.cpp index 1eec728f..83ed5a02 100644 --- a/CPP/7zip/Archive/ArHandler.cpp +++ b/CPP/7zip/Archive/ArHandler.cpp @@ -343,16 +343,17 @@ HRESULT CHandler::ParseLongNames(IInStream *stream) if (item.Size > ((UInt32)1 << 30)) return S_FALSE; RINOK(stream->Seek(item.GetDataPos(), STREAM_SEEK_SET, NULL)); - size_t size = (size_t)item.Size; + const size_t size = (size_t)item.Size; CByteArr p(size); RINOK(ReadStream_FALSE(stream, p, size)); + for (i = 0; i < _items.Size(); i++) { - CItem &item = _items[i]; - if (item.Name[0] != '/') + CItem &item2 = _items[i]; + if (item2.Name[0] != '/') continue; - const char *ptr = item.Name.Ptr(1); + const char *ptr = item2.Name.Ptr(1); const char *end; UInt32 pos = ConvertStringToUInt32(ptr, &end); if (*end != 0 || end == ptr) @@ -369,8 +370,9 @@ HRESULT CHandler::ParseLongNames(IInStream *stream) break; pos++; } - item.Name.SetFrom((const char *)(p + start), pos - start); + item2.Name.SetFrom((const char *)(p + start), pos - start); } + _longNames_FileIndex = fileIndex; return S_OK; } diff --git a/CPP/7zip/Archive/Cab/CabHandler.cpp b/CPP/7zip/Archive/Cab/CabHandler.cpp index 31aa5e1d..5f145739 100644 --- a/CPP/7zip/Archive/Cab/CabHandler.cpp +++ b/CPP/7zip/Archive/Cab/CabHandler.cpp @@ -1017,11 +1017,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, for (; i < numItems; i++) { unsigned indexNext = allFilesMode ? i : indices[i]; - const CMvItem &mvItem = m_Database.Items[indexNext]; - const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex]; - if (item.IsDir()) + const CMvItem &mvItem2 = m_Database.Items[indexNext]; + const CItem &item2 = m_Database.Volumes[mvItem2.VolumeIndex].Items[mvItem2.ItemIndex]; + if (item2.IsDir()) continue; - int newFolderIndex = m_Database.GetFolderIndex(&mvItem); + int newFolderIndex = m_Database.GetFolderIndex(&mvItem2); if (newFolderIndex != folderIndex) break; @@ -1029,7 +1029,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, extractStatuses.Add(false); extractStatuses.Add(true); startIndex++; - curUnpack = item.GetEndOffset(); + curUnpack = item2.GetEndOffset(); } CFolderOutStream *cabFolderOutStream = new CFolderOutStream; @@ -1104,16 +1104,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, break; } - const CDatabaseEx &db = m_Database.Volumes[volIndex]; - const CFolder &folder = db.Folders[locFolderIndex]; + const CDatabaseEx &db2 = m_Database.Volumes[volIndex]; + const CFolder &folder2 = db2.Folders[locFolderIndex]; if (bl == 0) { - cabBlockInStreamSpec->ReservedSize = db.ArcInfo.GetDataBlockReserveSize(); - RINOK(db.Stream->Seek(db.StartPosition + folder.DataStart, STREAM_SEEK_SET, NULL)); + cabBlockInStreamSpec->ReservedSize = db2.ArcInfo.GetDataBlockReserveSize(); + RINOK(db2.Stream->Seek(db2.StartPosition + folder2.DataStart, STREAM_SEEK_SET, NULL)); } - if (bl == folder.NumDataBlocks) + if (bl == folder2.NumDataBlocks) { /* CFolder::NumDataBlocks (CFFOLDER::cCFData in CAB specification) is 16-bit. @@ -1138,7 +1138,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, cabBlockInStreamSpec->InitForNewBlock(); UInt32 packSize, unpackSize; - res = cabBlockInStreamSpec->PreRead(db.Stream, packSize, unpackSize); + res = cabBlockInStreamSpec->PreRead(db2.Stream, packSize, unpackSize); if (res == S_FALSE) break; RINOK(res); @@ -1180,7 +1180,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, UInt64 unpackSize64 = unpackSize; UInt32 packSizeChunk = cabBlockInStreamSpec->GetPackSizeAvail(); - switch (folder.GetMethod()) + switch (folder2.GetMethod()) { case NHeader::NMethod::kNone: res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackSize64, NULL); diff --git a/CPP/7zip/Archive/Chm/ChmHandler.cpp b/CPP/7zip/Archive/Chm/ChmHandler.cpp index 2a72e8e9..b890d8ff 100644 --- a/CPP/7zip/Archive/Chm/ChmHandler.cpp +++ b/CPP/7zip/Archive/Chm/ChmHandler.cpp @@ -154,7 +154,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val case kpidBlock: if (m_Database.LowLevel) prop = item.Section; - else if (item.Section != 0) + else if (item.Section != 0 && item.Section < m_Database.Sections.Size()) prop = m_Database.GetFolder(index); break; @@ -545,7 +545,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, currentTotalSize += item.Size; continue; } - const CSectionInfo §ion = m_Database.Sections[(unsigned)item.Section]; + + if (sectionIndex >= m_Database.Sections.Size()) + continue; + + const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex]; if (section.IsLzx()) { const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo; @@ -621,6 +625,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, continue; } + if (sectionIndex >= m_Database.Sections.Size()) + { + // we must report error here; + CMyComPtr<ISequentialOutStream> realOutStream; + RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); + if (!testMode && !realOutStream) + continue; + RINOK(extractCallback->PrepareOperation(askMode)); + RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kHeadersError)); + continue; + } + const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex]; if (!section.IsLzx()) diff --git a/CPP/7zip/Archive/Chm/ChmIn.cpp b/CPP/7zip/Archive/Chm/ChmIn.cpp index 6bdf2af4..02ecfadd 100644 --- a/CPP/7zip/Archive/Chm/ChmIn.cpp +++ b/CPP/7zip/Archive/Chm/ChmIn.cpp @@ -667,13 +667,15 @@ static int CompareFiles(const unsigned *p1, const unsigned *p2, void *param) return -1; if (isDir2) { - if (isDir1) - return MyCompare(*p1, *p2); - return 1; + if (!isDir1) + return 1; + } + else + { + RINOZ(MyCompare(item1.Section, item2.Section)); + RINOZ(MyCompare(item1.Offset, item2.Offset)); + RINOZ(MyCompare(item1.Size, item2.Size)); } - RINOZ(MyCompare(item1.Section, item2.Section)); - RINOZ(MyCompare(item1.Offset, item2.Offset)); - RINOZ(MyCompare(item1.Size, item2.Size)); return MyCompare(*p1, *p2); } @@ -716,6 +718,19 @@ bool CFilesDatabase::Check() return true; } +bool CFilesDatabase::CheckSectionRefs() +{ + FOR_VECTOR (i, Indices) + { + const CItem &item = Items[Indices[i]]; + if (item.Section == 0 || item.IsDir()) + continue; + if (item.Section >= Sections.Size()) + return false; + } + return true; +} + static int inline GetLog(UInt32 num) { for (int i = 0; i < 32; i++) @@ -745,10 +760,10 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database) } } - unsigned i; - for (i = 1; i < database.Sections.Size(); i++) + unsigned si; + for (si = 1; si < database.Sections.Size(); si++) { - CSectionInfo §ion = database.Sections[i]; + CSectionInfo §ion = database.Sections[si]; AString sectionPrefix = GetSectionPrefix(section.Name); { // Content @@ -993,6 +1008,8 @@ HRESULT CInArchive::Open2(IInStream *inStream, return S_OK; } RINOK(res); + if (!database.CheckSectionRefs()) + HeadersError = true; database.LowLevel = false; } catch(...) diff --git a/CPP/7zip/Archive/Chm/ChmIn.h b/CPP/7zip/Archive/Chm/ChmIn.h index 60852852..bf51616f 100644 --- a/CPP/7zip/Archive/Chm/ChmIn.h +++ b/CPP/7zip/Archive/Chm/ChmIn.h @@ -186,18 +186,24 @@ public: UInt64 GetFolder(unsigned fileIndex) const { const CItem &item = Items[Indices[fileIndex]]; - const CSectionInfo §ion = Sections[(unsigned)item.Section]; - if (section.IsLzx()) - return section.Methods[0].LzxInfo.GetFolder(item.Offset); + if (item.Section < Sections.Size()) + { + const CSectionInfo §ion = Sections[(unsigned)item.Section]; + if (section.IsLzx()) + return section.Methods[0].LzxInfo.GetFolder(item.Offset); + } return 0; } UInt64 GetLastFolder(unsigned fileIndex) const { const CItem &item = Items[Indices[fileIndex]]; - const CSectionInfo §ion = Sections[(unsigned)item.Section]; - if (section.IsLzx()) - return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1); + if (item.Section < Sections.Size()) + { + const CSectionInfo §ion = Sections[(unsigned)item.Section]; + if (section.IsLzx()) + return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1); + } return 0; } @@ -217,6 +223,7 @@ public: void SetIndices(); void Sort(); bool Check(); + bool CheckSectionRefs(); }; diff --git a/CPP/7zip/Archive/ComHandler.cpp b/CPP/7zip/Archive/ComHandler.cpp index 2798bd71..c6d2bd25 100644 --- a/CPP/7zip/Archive/ComHandler.cpp +++ b/CPP/7zip/Archive/ComHandler.cpp @@ -167,7 +167,7 @@ HRESULT CDatabase::ReadSector(IInStream *inStream, Byte *buf, unsigned sectorSiz { UpdatePhySize(((UInt64)sid + 2) << sectorSizeBits); RINOK(inStream->Seek((((UInt64)sid + 1) << sectorSizeBits), STREAM_SEEK_SET, NULL)); - return ReadStream_FALSE(inStream, buf, (UInt32)1 << sectorSizeBits); + return ReadStream_FALSE(inStream, buf, (size_t)1 << sectorSizeBits); } HRESULT CDatabase::ReadIDs(IInStream *inStream, Byte *buf, unsigned sectorSizeBits, UInt32 sid, UInt32 *dest) diff --git a/CPP/7zip/Archive/Common/HandlerOut.cpp b/CPP/7zip/Archive/Common/HandlerOut.cpp index 95381ea3..30ca73bd 100644 --- a/CPP/7zip/Archive/Common/HandlerOut.cpp +++ b/CPP/7zip/Archive/Common/HandlerOut.cpp @@ -81,7 +81,7 @@ HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIAN } UInt32 number; - int index = ParseStringToUInt32(name, number); + unsigned index = ParseStringToUInt32(name, number); UString realName = name.Ptr(index); if (index == 0) { diff --git a/CPP/7zip/Archive/CramfsHandler.cpp b/CPP/7zip/Archive/CramfsHandler.cpp index 020f84b7..0f123321 100644 --- a/CPP/7zip/Archive/CramfsHandler.cpp +++ b/CPP/7zip/Archive/CramfsHandler.cpp @@ -583,13 +583,13 @@ HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize) } } - bool be = _h.be; - const Byte *p = _data + (_curBlocksOffset + (UInt32)blockIndex * 4); - UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p - 4)); - UInt32 end = Get32(p); + const bool be = _h.be; + const Byte *p2 = _data + (_curBlocksOffset + (UInt32)blockIndex * 4); + const UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p2 - 4)); + const UInt32 end = Get32(p2); if (end < start || end > _size) return S_FALSE; - UInt32 inSize = end - start; + const UInt32 inSize = end - start; if (_method == k_Flags_Method_LZMA) { @@ -707,7 +707,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, { RINOK(hres); { - HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress); + hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress); if (hres == S_OK) { if (copyCoderSpec->TotalSize == curSize) diff --git a/CPP/7zip/Archive/ExtHandler.cpp b/CPP/7zip/Archive/ExtHandler.cpp index 606aeed1..6c2cd726 100644 --- a/CPP/7zip/Archive/ExtHandler.cpp +++ b/CPP/7zip/Archive/ExtHandler.cpp @@ -2810,7 +2810,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, { RINOK(hres); { - HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress); + hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress); if (hres == S_OK) { if (copyCoderSpec->TotalSize == unpackSize) diff --git a/CPP/7zip/Archive/HfsHandler.cpp b/CPP/7zip/Archive/HfsHandler.cpp index 057a2d79..abf8bef6 100644 --- a/CPP/7zip/Archive/HfsHandler.cpp +++ b/CPP/7zip/Archive/HfsHandler.cpp @@ -876,7 +876,7 @@ HRESULT CDatabase::LoadCatalog(const CFork &fork, const CObjectVector<CIdExtents // CNodeDescriptor nodeDesc; // nodeDesc.Parse(p); CHeaderRec hr; - hr.Parse(p + kNodeDescriptor_Size); + RINOK(hr.Parse(p + kNodeDescriptor_Size)); // CaseSensetive = (Header.IsHfsX() && hr.KeyCompareType == 0xBC); @@ -1764,7 +1764,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, if (rem == 0) { // Here we check that there are no extra (empty) blocks in last extent. - if (extentRem >= (UInt64)((UInt32)1 << Header.BlockSizeLog)) + if (extentRem >= ((UInt64)1 << Header.BlockSizeLog)) res = NExtract::NOperationResult::kDataError; break; } diff --git a/CPP/7zip/Archive/Iso/IsoHandler.cpp b/CPP/7zip/Archive/Iso/IsoHandler.cpp index 91bf1a25..14aec498 100644 --- a/CPP/7zip/Archive/Iso/IsoHandler.cpp +++ b/CPP/7zip/Archive/Iso/IsoHandler.cpp @@ -358,7 +358,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream) UInt64 blockIndex; UInt64 currentItemSize; - if (index < (UInt32)_archive.Refs.Size()) + if (index < _archive.Refs.Size()) { const CRef &ref = _archive.Refs[index]; const CDir &item = ref.Dir->_subItems[ref.Index]; @@ -375,14 +375,14 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream) UInt64 virtOffset = 0; for (UInt32 i = 0; i < ref.NumExtents; i++) { - const CDir &item = ref.Dir->_subItems[ref.Index + i]; - if (item.Size == 0) + const CDir &item2 = ref.Dir->_subItems[ref.Index + i]; + if (item2.Size == 0) continue; CSeekExtent se; - se.Phy = (UInt64)item.ExtentLocation * kBlockSize; + se.Phy = (UInt64)item2.ExtentLocation * kBlockSize; se.Virt = virtOffset; extentStreamSpec->Extents.Add(se); - virtOffset += item.Size; + virtOffset += item2.Size; } if (virtOffset != ref.TotalSize) return S_FALSE; @@ -394,6 +394,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream) *stream = extentStream.Detach(); return S_OK; } + currentItemSize = item.Size; blockIndex = item.ExtentLocation; } diff --git a/CPP/7zip/Archive/NtfsHandler.cpp b/CPP/7zip/Archive/NtfsHandler.cpp index 25f4c8a6..93e9f88f 100644 --- a/CPP/7zip/Archive/NtfsHandler.cpp +++ b/CPP/7zip/Archive/NtfsHandler.cpp @@ -630,24 +630,27 @@ static size_t Lznt1Dec(Byte *dest, size_t outBufLim, size_t destLen, const Byte { if (srcLen < 2 || (destSize & 0xFFF) != 0) break; - UInt32 v = Get16(src); - if (v == 0) - break; - src += 2; - srcLen -= 2; - UInt32 comprSize = (v & 0xFFF) + 1; - if (comprSize > srcLen) - break; - srcLen -= comprSize; - if ((v & 0x8000) == 0) + UInt32 comprSize; { - if (comprSize != (1 << 12)) + const UInt32 v = Get16(src); + if (v == 0) + break; + src += 2; + srcLen -= 2; + comprSize = (v & 0xFFF) + 1; + if (comprSize > srcLen) break; - memcpy(dest + destSize, src, comprSize); - src += comprSize; - destSize += comprSize; + srcLen -= comprSize; + if ((v & 0x8000) == 0) + { + if (comprSize != (1 << 12)) + break; + memcpy(dest + destSize, src, comprSize); + src += comprSize; + destSize += comprSize; + continue; + } } - else { if (destSize + (1 << 12) > outBufLim || (src[0] & 1) != 0) return 0; @@ -672,7 +675,7 @@ static size_t Lznt1Dec(Byte *dest, size_t outBufLim, size_t destLen, const Byte { if (comprSize < 2) return 0; - UInt32 v = Get16(src + pos); + const UInt32 v = Get16(src + pos); pos += 2; comprSize -= 2; @@ -709,9 +712,12 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize) return (Size == _virtPos) ? S_OK: E_FAIL; if (size == 0) return S_OK; - UInt64 rem = Size - _virtPos; - if (size > rem) - size = (UInt32)rem; + { + const UInt64 rem = Size - _virtPos; + if (size > rem) + size = (UInt32)rem; + } + if (_virtPos >= InitializedSize) { memset((Byte *)data, 0, size); @@ -719,9 +725,12 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize) *processedSize = size; return S_OK; } - rem = InitializedSize - _virtPos; - if (size > rem) - size = (UInt32)rem; + + { + const UInt64 rem = InitializedSize - _virtPos; + if (size > rem) + size = (UInt32)rem; + } while (_curRem == 0) { @@ -838,7 +847,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize) } size_t destLenMax = GetCuSize(); size_t destLen = destLenMax; - UInt64 rem = Size - (virtBlock2 << BlockSizeLog); + const UInt64 rem = Size - (virtBlock2 << BlockSizeLog); if (destLen > rem) destLen = (size_t)rem; @@ -895,10 +904,13 @@ STDMETHODIMP CInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPositio static HRESULT DataParseExtents(unsigned clusterSizeLog, const CObjectVector<CAttr> &attrs, unsigned attrIndex, unsigned attrIndexLim, UInt64 numPhysClusters, CRecordVector<CExtent> &Extents) { - CExtent e; - e.Virt = 0; - e.Phy = kEmptyExtent; - Extents.Add(e); + { + CExtent e; + e.Virt = 0; + e.Phy = kEmptyExtent; + Extents.Add(e); + } + const CAttr &attr0 = attrs[attrIndex]; if (attr0.AllocatedSize < attr0.Size || @@ -1075,20 +1087,22 @@ HRESULT CMftRec::GetStream(IInStream *mainStream, int dataIndex, { if (numNonResident != ref.Num || !attr0.IsCompressionUnitSupported()) return S_FALSE; - CInStream *streamSpec = new CInStream; - CMyComPtr<IInStream> streamTemp = streamSpec; - RINOK(DataParseExtents(clusterSizeLog, DataAttrs, ref.Start, ref.Start + ref.Num, numPhysClusters, streamSpec->Extents)); - streamSpec->Size = attr0.Size; - streamSpec->InitializedSize = attr0.InitializedSize; - streamSpec->Stream = mainStream; - streamSpec->BlockSizeLog = clusterSizeLog; - streamSpec->InUse = InUse(); - RINOK(streamSpec->InitAndSeek(attr0.CompressionUnit)); - *destStream = streamTemp.Detach(); + CInStream *ss = new CInStream; + CMyComPtr<IInStream> streamTemp2 = ss; + RINOK(DataParseExtents(clusterSizeLog, DataAttrs, ref.Start, ref.Start + ref.Num, numPhysClusters, ss->Extents)); + ss->Size = attr0.Size; + ss->InitializedSize = attr0.InitializedSize; + ss->Stream = mainStream; + ss->BlockSizeLog = clusterSizeLog; + ss->InUse = InUse(); + RINOK(ss->InitAndSeek(attr0.CompressionUnit)); + *destStream = streamTemp2.Detach(); return S_OK; } + streamSpec->Buf = attr0.Data; } + streamSpec->Init(); *destStream = streamTemp.Detach(); return S_OK; @@ -1691,36 +1705,40 @@ HRESULT CDatabase::Open() if ((mftSize >> 4) > Header.GetPhySize_Clusters()) return S_FALSE; - UInt64 numFiles = mftSize >> RecSizeLog; - if (numFiles > (1 << 30)) - return S_FALSE; - if (OpenCallback) - { - RINOK(OpenCallback->SetTotal(&numFiles, &mftSize)); - } - const size_t kBufSize = (1 << 15); const size_t recSize = ((size_t)1 << RecSizeLog); if (kBufSize < recSize) return S_FALSE; - ByteBuf.Alloc(kBufSize); - Recs.ClearAndReserve((unsigned)numFiles); + { + const UInt64 numFiles = mftSize >> RecSizeLog; + if (numFiles > (1 << 30)) + return S_FALSE; + if (OpenCallback) + { + RINOK(OpenCallback->SetTotal(&numFiles, &mftSize)); + } + + ByteBuf.Alloc(kBufSize); + Recs.ClearAndReserve((unsigned)numFiles); + } for (UInt64 pos64 = 0;;) { if (OpenCallback) { - UInt64 numFiles = Recs.Size(); + const UInt64 numFiles = Recs.Size(); if ((numFiles & 0x3FF) == 0) { RINOK(OpenCallback->SetCompleted(&numFiles, &pos64)); } } size_t readSize = kBufSize; - UInt64 rem = mftSize - pos64; - if (readSize > rem) - readSize = (size_t)rem; + { + const UInt64 rem = mftSize - pos64; + if (readSize > rem) + readSize = (size_t)rem; + } if (readSize < recSize) break; RINOK(ReadStream_FALSE(mftStream, ByteBuf, readSize)); @@ -2668,7 +2686,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, RINOK(hres); if (inStream) { - HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress); + hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress); if (hres != S_OK && hres != S_FALSE) { RINOK(hres); diff --git a/CPP/7zip/Archive/PeHandler.cpp b/CPP/7zip/Archive/PeHandler.cpp index 160648f6..51087166 100644 --- a/CPP/7zip/Archive/PeHandler.cpp +++ b/CPP/7zip/Archive/PeHandler.cpp @@ -242,7 +242,7 @@ struct COptHeader int GetNumFileAlignBits() const { - for (int i = 9; i <= 16; i++) + for (unsigned i = 0; i <= 31; i++) if (((UInt32)1 << i) == FileAlign) return i; return -1; @@ -1154,7 +1154,7 @@ HRESULT CHandler::ReadTable(UInt32 offset, CRecordVector<CTableItem> &items) return S_OK; } -static const UInt32 kFileSizeMax = (UInt32)1 << 30; +static const UInt32 kFileSizeMax = (UInt32)1 << 31; static const unsigned kNumResItemsMax = (unsigned)1 << 23; static const unsigned kNumStringLangsMax = 256; @@ -1898,25 +1898,61 @@ static bool ParseVersion(const Byte *p, UInt32 size, CTextFile &f, CObjectVector HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchiveOpenCallback *callback) { const CSection § = _sections[sectionIndex]; - const size_t fileSize = sect.GetSizeMin(); - - if (fileSize > kFileSizeMax) - return S_FALSE; + size_t fileSize = sect.PSize; { - UInt64 fileSize64 = fileSize; - if (callback) - RINOK(callback->SetTotal(NULL, &fileSize64)); + size_t fileSizeMin = sect.PSize; + + if (sect.VSize < sect.PSize) + { + fileSize = fileSizeMin = sect.VSize; + const int numBits = _optHeader.GetNumFileAlignBits(); + if (numBits > 0) + { + const UInt32 mask = ((UInt32)1 << numBits) - 1; + const size_t end = (size_t)((sect.VSize + mask) & (UInt32)~mask); + if (end > sect.VSize) + if (end <= sect.PSize) + fileSize = end; + else + fileSize = sect.PSize; + } + } + + if (fileSize > kFileSizeMax) + return S_FALSE; + + { + const UInt64 fileSize64 = fileSize; + if (callback) + RINOK(callback->SetTotal(NULL, &fileSize64)); + } + RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL)); + _buf.Alloc(fileSize); - for (size_t pos = 0; pos < fileSize;) + + size_t pos; + + for (pos = 0; pos < fileSize;) { - UInt64 offset64 = pos; - if (callback) - RINOK(callback->SetCompleted(NULL, &offset64)) + { + const UInt64 offset64 = pos; + if (callback) + RINOK(callback->SetCompleted(NULL, &offset64)) + } size_t rem = MyMin(fileSize - pos, (size_t)(1 << 22)); - RINOK(ReadStream_FALSE(stream, _buf + pos, rem)); + RINOK(ReadStream(stream, _buf + pos, &rem)); + if (rem == 0) + { + if (pos < fileSizeMin) + return S_FALSE; + break; + } pos += rem; } + + if (pos < fileSize) + memset(_buf + pos, 0, fileSize - pos); } _usedRes.Alloc(fileSize); @@ -2037,19 +2073,13 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi _usedRes.Free(); - int numBits = _optHeader.GetNumFileAlignBits(); - if (numBits >= 0) { - UInt32 mask = (1 << numBits) - 1; - size_t end = ((maxOffset + mask) & ~mask); - // PSize can be much larger than VSize in some exe installers. // it contains archive data after PE resources. // So we need to use PSize here! - if (/* end < sect.VSize && */ end <= sect.PSize) + if (maxOffset < sect.PSize) { - CSection sect2; - sect2.Flags = 0; + size_t end = fileSize; // we skip Zeros to start of aligned block size_t i; @@ -2059,6 +2089,8 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi if (i == end) maxOffset = end; + CSection sect2; + sect2.Flags = 0; sect2.Pa = sect.Pa + (UInt32)maxOffset; sect2.Va = sect.Va + (UInt32)maxOffset; @@ -2211,14 +2243,14 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback) } */ - size_t i; - for (i = 0; i < processed; i++) - if (buf[i] != 0) + size_t k; + for (k = 0; k < processed; k++) + if (buf[k] != 0) break; if (processed < size && processed < 100) _totalSize += (UInt32)processed; - else if (((_totalSize + i) & 0x1FF) == 0 || processed < size) - _totalSize += (UInt32)i; + else if (((_totalSize + k) & 0x1FF) == 0 || processed < size) + _totalSize += (UInt32)k; } } @@ -2248,9 +2280,9 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback) sections.Sort(); UInt32 limit = (1 << 12); unsigned num = 0; - FOR_VECTOR (i, sections) + FOR_VECTOR (k, sections) { - const CSection &s = sections[i]; + const CSection &s = sections[k]; if (s.Pa > limit) { CSection &s2 = _sections.AddNew(); diff --git a/CPP/7zip/Archive/QcowHandler.cpp b/CPP/7zip/Archive/QcowHandler.cpp index 42c0a511..a84fdc9b 100644 --- a/CPP/7zip/Archive/QcowHandler.cpp +++ b/CPP/7zip/Archive/QcowHandler.cpp @@ -463,22 +463,26 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *openCallback) RINOK(openCallback->SetCompleted(NULL, &numBytes)); } - UInt64 v = Get64((const Byte *)table + (size_t)i * 8); - v &= offsetMask; - CByteBuffer &buf = _tables.AddNew(); - if (v == 0) - continue; - - buf.Alloc((size_t)1 << (_numMidBits + 3)); - RINOK(stream->Seek(v, STREAM_SEEK_SET, NULL)); - RINOK(ReadStream_FALSE(stream, buf, clusterSize)); - UInt64 end = v + clusterSize; - if (_phySize < end) - _phySize = end; + CByteBuffer &buf2 = _tables.AddNew(); + + { + UInt64 v = Get64((const Byte *)table + (size_t)i * 8); + v &= offsetMask; + if (v == 0) + continue; + + buf2.Alloc((size_t)1 << (_numMidBits + 3)); + RINOK(stream->Seek(v, STREAM_SEEK_SET, NULL)); + RINOK(ReadStream_FALSE(stream, buf2, clusterSize)); + + const UInt64 end = v + clusterSize; + if (_phySize < end) + _phySize = end; + } for (size_t k = 0; k < clusterSize; k += 8) { - UInt64 v = Get64((const Byte *)buf + (size_t)k); + const UInt64 v = Get64((const Byte *)buf2 + (size_t)k); if (v == 0) continue; UInt64 offset = v & offsetMask; diff --git a/CPP/7zip/Archive/Rar/Rar5Handler.cpp b/CPP/7zip/Archive/Rar/Rar5Handler.cpp index 959c2e36..4fb63505 100644 --- a/CPP/7zip/Archive/Rar/Rar5Handler.cpp +++ b/CPP/7zip/Archive/Rar/Rar5Handler.cpp @@ -189,8 +189,8 @@ bool CItem::FindExtra_Version(UInt64 &version) const return false; const Byte *p = Extra + (unsigned)offset; - UInt64 Flags; - unsigned num = ReadVarInt(p, size, &Flags); + UInt64 flags; + unsigned num = ReadVarInt(p, size, &flags); if (num == 0) return false; p += num; size -= num; num = ReadVarInt(p, size, &version); @@ -1881,6 +1881,7 @@ HRESULT CHandler::Open2(IInStream *stream, } CInArcInfo arcInfoOpen; + { HRESULT res = arch.Open(inStream, maxCheckStartPosition, getTextPassword, arcInfoOpen); if (arch.IsArc && arch.UnexpectedEnd) _errorFlags |= kpv_ErrorFlags_UnexpectedEnd; @@ -1897,6 +1898,7 @@ HRESULT CHandler::Open2(IInStream *stream, return res; break; } + } CArc &arc = _arcs.AddNew(); CInArcInfo &arcInfo = arc.Info; @@ -2068,12 +2070,12 @@ HRESULT CHandler::Open2(IInStream *stream, { if (prevSplitFile >= 0) { - CRefItem &ref = _refs[prevSplitFile]; - CItem &prevItem = _items[ref.Last]; + CRefItem &ref2 = _refs[prevSplitFile]; + CItem &prevItem = _items[ref2.Last]; if (item.IsNextForItem(prevItem)) { - ref.Last = _items.Size(); - prevItem.NextItem = ref.Last; + ref2.Last = _items.Size(); + prevItem.NextItem = ref2.Last; needAdd = false; } } diff --git a/CPP/7zip/Archive/Rar/RarHandler.cpp b/CPP/7zip/Archive/Rar/RarHandler.cpp index 6f3e0a0c..71237c93 100644 --- a/CPP/7zip/Archive/Rar/RarHandler.cpp +++ b/CPP/7zip/Archive/Rar/RarHandler.cpp @@ -1602,11 +1602,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, if (len > kPasswordLen_MAX) len = kPasswordLen_MAX; CByteArr buffer(len * 2); - for (unsigned i = 0; i < len; i++) + for (unsigned k = 0; k < len; k++) { - wchar_t c = password[i]; - ((Byte *)buffer)[i * 2] = (Byte)c; - ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8); + wchar_t c = password[k]; + ((Byte *)buffer)[k * 2] = (Byte)c; + ((Byte *)buffer)[k * 2 + 1] = (Byte)(c >> 8); } rar3CryptoDecoderSpec->SetPassword((const Byte *)buffer, len * 2); } diff --git a/CPP/7zip/Archive/SquashfsHandler.cpp b/CPP/7zip/Archive/SquashfsHandler.cpp index fc195717..5ddfae3f 100644 --- a/CPP/7zip/Archive/SquashfsHandler.cpp +++ b/CPP/7zip/Archive/SquashfsHandler.cpp @@ -296,23 +296,25 @@ struct CNode UInt32 CNode::Parse1(const Byte *p, UInt32 size, const CHeader &_h) { - bool be = _h.be; + const bool be = _h.be; if (size < 4) return 0; - UInt16 t = Get16(p); - if (be) { - Type = (UInt16)(t >> 12); - Mode = (UInt16)(t & 0xFFF); - Uid = (UInt16)(p[2] >> 4); - Gid = (UInt16)(p[2] & 0xF); - } - else - { - Type = (UInt16)(t & 0xF); - Mode = (UInt16)(t >> 4); - Uid = (UInt16)(p[2] & 0xF); - Gid = (UInt16)(p[2] >> 4); + const UInt32 t = Get16(p); + if (be) + { + Type = (UInt16)(t >> 12); + Mode = (UInt16)(t & 0xFFF); + Uid = (UInt16)(p[2] >> 4); + Gid = (UInt16)(p[2] & 0xF); + } + else + { + Type = (UInt16)(t & 0xF); + Mode = (UInt16)(t >> 4); + Uid = (UInt16)(p[2] & 0xF); + Gid = (UInt16)(p[2] >> 4); + } } // Xattr = kXattr_Empty; @@ -402,17 +404,20 @@ UInt32 CNode::Parse2(const Byte *p, UInt32 size, const CHeader &_h) bool be = _h.be; if (size < 4) return 0; - UInt16 t = Get16(p); - if (be) - { - Type = (UInt16)(t >> 12); - Mode = (UInt16)(t & 0xFFF); - } - else { - Type = (UInt16)(t & 0xF); - Mode = (UInt16)(t >> 4); + const UInt32 t = Get16(p); + if (be) + { + Type = (UInt16)(t >> 12); + Mode = (UInt16)(t & 0xFFF); + } + else + { + Type = (UInt16)(t & 0xF); + Mode = (UInt16)(t >> 4); + } } + Uid = p[2]; Gid = p[3]; @@ -532,17 +537,21 @@ UInt32 CNode::Parse3(const Byte *p, UInt32 size, const CHeader &_h) bool be = _h.be; if (size < 12) return 0; - UInt16 t = Get16(p); - if (be) - { - Type = (UInt16)(t >> 12); - Mode = (UInt16)(t & 0xFFF); - } - else + { - Type = (UInt16)(t & 0xF); - Mode = (UInt16)(t >> 4); + const UInt32 t = Get16(p); + if (be) + { + Type = (UInt16)(t >> 12); + Mode = (UInt16)(t & 0xFFF); + } + else + { + Type = (UInt16)(t & 0xF); + Mode = (UInt16)(t >> 4); + } } + Uid = p[2]; Gid = p[3]; // GET_32 (4, MTime); @@ -2115,7 +2124,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, { RINOK(hres); { - HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress); + hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress); if (hres == S_OK) { if (copyCoderSpec->TotalSize == unpackSize) diff --git a/CPP/7zip/Archive/Udf/UdfIn.cpp b/CPP/7zip/Archive/Udf/UdfIn.cpp index 908f2356..d52db9f4 100644 --- a/CPP/7zip/Archive/Udf/UdfIn.cpp +++ b/CPP/7zip/Archive/Udf/UdfIn.cpp @@ -428,7 +428,7 @@ HRESULT CInArchive::ReadItem(int volIndex, int fsIndex, const CLongAllocDesc &la if (lad.GetLen() != vol.BlockSize) return S_FALSE; - size_t size = lad.GetLen(); + const size_t size = lad.GetLen(); CByteBuffer buf(size); RINOK(Read(volIndex, lad, buf)); @@ -518,20 +518,20 @@ HRESULT CInArchive::ReadItem(int volIndex, int fsIndex, const CLongAllocDesc &la { if (!item.CheckChunkSizes() || !CheckItemExtents(volIndex, item)) return S_FALSE; - CByteBuffer buf; - RINOK(ReadFromFile(volIndex, item, buf)); + CByteBuffer buf2; + RINOK(ReadFromFile(volIndex, item, buf2)); item.Size = 0; item.Extents.ClearAndFree(); item.InlineData.Free(); - const Byte *p = buf; - size = buf.Size(); + const Byte *p2 = buf2; + const size_t size2 = buf2.Size(); size_t processedTotal = 0; - for (; processedTotal < size;) + for (; processedTotal < size2;) { size_t processedCur; CFileId fileId; - RINOK(fileId.Parse(p + processedTotal, size - processedTotal, processedCur)); + RINOK(fileId.Parse(p2 + processedTotal, size2 - processedTotal, processedCur)); if (!fileId.IsItLinkParent()) { CFile file; @@ -599,8 +599,8 @@ API_FUNC_IsArc IsArc_Udf(const Byte *p, size_t size) { if (SecLogSize < 8) return res; - UInt32 offset = (UInt32)256 << SecLogSize; - size_t bufSize = (UInt32)1 << SecLogSize; + const UInt32 offset = (UInt32)256 << SecLogSize; + const UInt32 bufSize = (UInt32)1 << SecLogSize; if (offset + bufSize > size) res = k_IsArc_Res_NEED_MORE; else @@ -660,7 +660,7 @@ HRESULT CInArchive::Open2() if (offset >= fileSize) continue; RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL)); - size_t bufSize = (UInt32)1 << SecLogSize; + const size_t bufSize = (size_t)1 << SecLogSize; size_t readSize = bufSize; RINOK(ReadStream(_stream, buf, &readSize)); if (readSize == bufSize) @@ -686,8 +686,7 @@ HRESULT CInArchive::Open2() for (UInt32 location = 0; ; location++) { - size_t bufSize = (UInt32)1 << SecLogSize; - size_t pos = 0; + const size_t bufSize = (size_t)1 << SecLogSize; if (((UInt64)(location + 1) << SecLogSize) > extentVDS.Len) return S_FALSE; @@ -700,7 +699,10 @@ HRESULT CInArchive::Open2() CTag tag; - RINOK(tag.Parse(buf + pos, bufSize - pos)); + { + const size_t pos = 0; + RINOK(tag.Parse(buf + pos, bufSize - pos)); + } if (tag.Id == DESC_TYPE_Terminating) break; @@ -862,9 +864,9 @@ HRESULT CInArchive::Open2() { if (nextExtent.GetLen() < 512) return S_FALSE; - CByteBuffer buf(nextExtent.GetLen()); - RINOK(Read(volIndex, nextExtent, buf)); - const Byte *p = buf; + CByteBuffer buf2(nextExtent.GetLen()); + RINOK(Read(volIndex, nextExtent, buf2)); + const Byte *p = buf2; size_t size = nextExtent.GetLen(); CTag tag; diff --git a/CPP/7zip/Archive/UefiHandler.cpp b/CPP/7zip/Archive/UefiHandler.cpp index 015a9caa..80692493 100644 --- a/CPP/7zip/Archive/UefiHandler.cpp +++ b/CPP/7zip/Archive/UefiHandler.cpp @@ -702,9 +702,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val int cur = item2.Parent; while (cur >= 0) { - const CItem2 &item2 = _items2[cur]; - path = item2.Name + CHAR_PATH_SEPARATOR + path; - cur = item2.Parent; + const CItem2 &item3 = _items2[cur]; + path.InsertAtFront(CHAR_PATH_SEPARATOR); + path.Insert(0, item3.Name); + cur = item3.Parent; } prop = path; break; diff --git a/CPP/7zip/Archive/VhdHandler.cpp b/CPP/7zip/Archive/VhdHandler.cpp index bddbf31b..12cbfa04 100644 --- a/CPP/7zip/Archive/VhdHandler.cpp +++ b/CPP/7zip/Archive/VhdHandler.cpp @@ -532,9 +532,11 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize) *processedSize = 0; if (_virtPos >= Footer.CurrentSize) return S_OK; - UInt64 rem = Footer.CurrentSize - _virtPos; - if (size > rem) - size = (UInt32)rem; + { + const UInt64 rem = Footer.CurrentSize - _virtPos; + if (size > rem) + size = (UInt32)rem; + } if (size == 0) return S_OK; UInt32 blockIndex = (UInt32)(_virtPos >> Dyn.BlockSizeLog); @@ -565,7 +567,7 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize) RINOK(ReadPhy(newPos + BitMap.Size() + offsetInBlock, data, size)); for (UInt32 cur = 0; cur < size;) { - UInt32 rem = MyMin(0x200 - (offsetInBlock & 0x1FF), size - cur); + const UInt32 rem = MyMin(0x200 - (offsetInBlock & 0x1FF), size - cur); UInt32 bmi = offsetInBlock >> kSectorSize_Log; if (((BitMap[bmi >> 3] >> (7 - (bmi & 7))) & 1) == 0) { diff --git a/CPP/7zip/Archive/VmdkHandler.cpp b/CPP/7zip/Archive/VmdkHandler.cpp index 359691e3..5f93c738 100644 --- a/CPP/7zip/Archive/VmdkHandler.cpp +++ b/CPP/7zip/Archive/VmdkHandler.cpp @@ -1349,43 +1349,45 @@ HRESULT CExtent::Open3(IInStream *stream, IArchiveOpenCallback *openCallback, for (size_t i = 0; i < numGdeEntries; i++) { - UInt32 v = Get32((const Byte *)table + (size_t)i * 4); + const size_t k_NumSectors = (size_t)1 << (k_NumMidBits - 9 + 2); + const size_t k_NumMidItems = (size_t)1 << k_NumMidBits; + CByteBuffer &buf = Tables.AddNew(); - if (v == 0 || v == ZeroSector) - continue; - if (openCallback && (i - numProcessed_Prev) >= 1024) - { - const UInt64 comp = complexityStart + ((UInt64)i << (k_NumMidBits + 2)); - const UInt64 volIndex2 = volIndex; - RINOK(openCallback->SetCompleted(numVols == 1 ? NULL : &volIndex2, &comp)); - numProcessed_Prev = i; - } - const size_t k_NumSectors = (size_t)1 << (k_NumMidBits - 9 + 2); - - if (h.Is_Marker()) { - Byte buf2[1 << 9]; - if (ReadForHeader(stream, v - 1, buf2, 1) != S_OK) - return S_FALSE; + const UInt32 v = Get32((const Byte *)table + (size_t)i * 4); + if (v == 0 || v == ZeroSector) + continue; + if (openCallback && (i - numProcessed_Prev) >= 1024) { - CMarker m; - m.Parse(buf2); - if (m.Type != k_Marker_GRAIN_TABLE + const UInt64 comp = complexityStart + ((UInt64)i << (k_NumMidBits + 2)); + const UInt64 volIndex2 = volIndex; + RINOK(openCallback->SetCompleted(numVols == 1 ? NULL : &volIndex2, &comp)); + numProcessed_Prev = i; + } + + if (h.Is_Marker()) + { + Byte buf2[1 << 9]; + if (ReadForHeader(stream, v - 1, buf2, 1) != S_OK) + return S_FALSE; + { + CMarker m; + m.Parse(buf2); + if (m.Type != k_Marker_GRAIN_TABLE || m.NumSectors != k_NumSectors || m.SpecSize != 0) - return S_FALSE; + return S_FALSE; + } } + + buf.Alloc(k_NumMidItems * 4); + RINOK(ReadForHeader(stream, v, buf, k_NumSectors)); } - const size_t k_NumMidItems = (size_t)1 << k_NumMidBits; - - buf.Alloc(k_NumMidItems * 4); - RINOK(ReadForHeader(stream, v, buf, k_NumSectors)); - for (size_t k = 0; k < k_NumMidItems; k++) { - UInt32 v = Get32((const Byte *)buf + (size_t)k * 4); + const UInt32 v = Get32((const Byte *)buf + (size_t)k * 4); if (v == 0 || v == ZeroSector) continue; if (v < h.overHead) diff --git a/CPP/7zip/Archive/Wim/WimHandler.cpp b/CPP/7zip/Archive/Wim/WimHandler.cpp index e6bc21f6..d4f53b9c 100644 --- a/CPP/7zip/Archive/Wim/WimHandler.cpp +++ b/CPP/7zip/Archive/Wim/WimHandler.cpp @@ -130,9 +130,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) int index = -1; FOR_VECTOR (i, xml.Images) { - const CImageInfo &image = xml.Images[i]; - if (image.CTimeDefined) - if (index < 0 || ::CompareFileTime(&image.CTime, &xml.Images[index].CTime) < 0) + const CImageInfo &image2 = xml.Images[i]; + if (image2.CTimeDefined) + if (index < 0 || ::CompareFileTime(&image2.CTime, &xml.Images[index].CTime) < 0) index = i; } if (index >= 0) @@ -147,9 +147,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) int index = -1; FOR_VECTOR (i, xml.Images) { - const CImageInfo &image = xml.Images[i]; - if (image.MTimeDefined) - if (index < 0 || ::CompareFileTime(&image.MTime, &xml.Images[index].MTime) > 0) + const CImageInfo &image2 = xml.Images[i]; + if (image2.MTimeDefined) + if (index < 0 || ::CompareFileTime(&image2.MTime, &xml.Images[index].MTime) > 0) index = i; } if (index >= 0) @@ -158,7 +158,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) break; case kpidComment: - if (image != NULL) + if (image) { if (_xmlInComments) { diff --git a/CPP/7zip/Archive/Wim/WimHandlerOut.cpp b/CPP/7zip/Archive/Wim/WimHandlerOut.cpp index 2eb6c94b..1d198df0 100644 --- a/CPP/7zip/Archive/Wim/WimHandlerOut.cpp +++ b/CPP/7zip/Archive/Wim/WimHandlerOut.cpp @@ -1351,9 +1351,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu header.ChunkSizeBits = srcHeader.ChunkSizeBits; } - Byte buf[kHeaderSizeMax]; - header.WriteTo(buf); - RINOK(WriteStream(outStream, buf, kHeaderSizeMax)); + { + Byte buf[kHeaderSizeMax]; + header.WriteTo(buf); + RINOK(WriteStream(outStream, buf, kHeaderSizeMax)); + } UInt64 curPos = kHeaderSizeMax; @@ -1754,14 +1756,14 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu } else { - unsigned i; - for (i = 0; i < secBufs.Size(); i++, pos += 8) + unsigned k; + for (k = 0; k < secBufs.Size(); k++, pos += 8) { - Set64(meta + pos, secBufs[i].Size()); + Set64(meta + pos, secBufs[k].Size()); } - for (i = 0; i < secBufs.Size(); i++) + for (k = 0; k < secBufs.Size(); k++) { - const CByteBuffer &buf = secBufs[i]; + const CByteBuffer &buf = secBufs[k]; size_t size = buf.Size(); if (size != 0) { @@ -1888,8 +1890,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu outStream->Seek(0, STREAM_SEEK_SET, NULL); header.NumImages = trees.Size(); - header.WriteTo(buf); - return WriteStream(outStream, buf, kHeaderSizeMax); + { + Byte buf[kHeaderSizeMax]; + header.WriteTo(buf); + return WriteStream(outStream, buf, kHeaderSizeMax); + } COM_TRY_END } diff --git a/CPP/7zip/Archive/Wim/WimIn.cpp b/CPP/7zip/Archive/Wim/WimIn.cpp index b1bed3c6..f35c2d50 100644 --- a/CPP/7zip/Archive/Wim/WimIn.cpp +++ b/CPP/7zip/Archive/Wim/WimIn.cpp @@ -589,7 +589,7 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent) RINOK(OpenCallback->SetCompleted(&numFiles, NULL)); } - size_t rem = DirSize - pos; + const size_t rem = DirSize - pos; if (pos < DirStartOffset || pos > DirSize || rem < 8) return S_FALSE; @@ -661,15 +661,15 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent) for (UInt32 i = 0; i < numAltStreams; i++) { - const size_t rem = DirSize - pos; - if (pos < DirStartOffset || pos > DirSize || rem < 8) + const size_t rem2 = DirSize - pos; + if (pos < DirStartOffset || pos > DirSize || rem2 < 8) return S_FALSE; - const Byte *p = DirData + pos; - const UInt64 len = Get64(p); - if ((len & align) != 0 || rem < len || len < (IsOldVersion ? 0x18 : 0x28)) + const Byte *p2 = DirData + pos; + const UInt64 len2 = Get64(p2); + if ((len2 & align) != 0 || rem2 < len2 || len2 < (IsOldVersion ? 0x18 : 0x28)) return S_FALSE; - DirProcessed += (size_t)len; + DirProcessed += (size_t)len2; if (DirProcessed > DirSize) return S_FALSE; @@ -679,29 +679,29 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent) extraOffset = 0x10; else { - if (Get64(p + 8) != 0) + if (Get64(p2 + 8) != 0) return S_FALSE; extraOffset = 0x24; } - UInt32 fileNameLen = Get16(p + extraOffset); - if ((fileNameLen & 1) != 0) + const UInt32 fileNameLen111 = Get16(p2 + extraOffset); + if ((fileNameLen111 & 1) != 0) return S_FALSE; /* Probably different versions of ImageX can use different number of additional ZEROs. So we don't use exact check. */ - UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2); - if (((extraOffset + 2 + fileNameLen2 + align) & ~align) > len) + const UInt32 fileNameLen222 = (fileNameLen111 == 0 ? fileNameLen111 : fileNameLen111 + 2); + if (((extraOffset + 2 + fileNameLen222 + align) & ~align) > len2) return S_FALSE; { - const Byte *p2 = p + extraOffset + 2; - if (*(const UInt16 *)(p2 + fileNameLen) != 0) + const Byte *p3 = p2 + extraOffset + 2; + if (*(const UInt16 *)(p3 + fileNameLen111) != 0) return S_FALSE; - for (UInt32 j = 0; j < fileNameLen; j += 2) - if (*(const UInt16 *)(p2 + j) == 0) + for (UInt32 j = 0; j < fileNameLen111; j += 2) + if (*(const UInt16 *)(p3 + j) == 0) return S_FALSE; - // PRF(printf("\n %S", p2)); + // PRF(printf("\n %S", p3)); } @@ -712,16 +712,16 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent) Byte *prevMeta = DirData + item.Offset; - if (fileNameLen == 0 && + if (fileNameLen111 == 0 && ((attrib & FILE_ATTRIBUTE_REPARSE_POINT) || !item.IsDir) && (IsOldVersion || IsEmptySha(prevMeta + 0x40))) { if (IsOldVersion) - memcpy(prevMeta + 0x10, p + 8, 4); // It's 32-bit Id - else if (!IsEmptySha(p + 0x10)) + memcpy(prevMeta + 0x10, p2 + 8, 4); // It's 32-bit Id + else if (!IsEmptySha(p2 + 0x10)) { // if (IsEmptySha(prevMeta + 0x40)) - memcpy(prevMeta + 0x40, p + 0x10, kHashSize); + memcpy(prevMeta + 0x40, p2 + 0x10, kHashSize); // else HeadersError = true; } } @@ -736,7 +736,7 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent) Items.Add(item2); } - pos += (size_t)len; + pos += (size_t)len2; } if (parent < 0 && numItems == 0 && shortNameLen == 0 && fileNameLen == 0 && item.IsDir) @@ -973,10 +973,15 @@ static HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db) RINOK(unpacker.UnpackData(inStream, h.OffsetResource, h, NULL, offsetBuf, NULL)); const size_t streamInfoSize = h.IsOldVersion() ? kStreamInfoSize + 2 : kStreamInfoSize; - unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize); - if ((size_t)numItems * streamInfoSize != offsetBuf.Size()) - return S_FALSE; - db.DataStreams.Reserve(numItems); + { + const unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize); + if ((size_t)numItems * streamInfoSize != offsetBuf.Size()) + return S_FALSE; + const unsigned numItems2 = db.DataStreams.Size() + numItems; + if (numItems2 < numItems) + return S_FALSE; + db.DataStreams.Reserve(numItems2); + } bool keepSolid = false; diff --git a/CPP/7zip/Archive/XarHandler.cpp b/CPP/7zip/Archive/XarHandler.cpp index 80111b6b..59196b18 100644 --- a/CPP/7zip/Archive/XarHandler.cpp +++ b/CPP/7zip/Archive/XarHandler.cpp @@ -486,14 +486,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val int cur = index; do { - const CFile &item = _files[cur]; + const CFile &item2 = _files[cur]; if (!path.IsEmpty()) path.InsertAtFront(CHAR_PATH_SEPARATOR); - if (item.Name.IsEmpty()) + if (item2.Name.IsEmpty()) path.Insert(0, "unknown"); else - path.Insert(0, item.Name); - cur = item.Parent; + path.Insert(0, item2.Name); + cur = item2.Parent; } while (cur >= 0); diff --git a/CPP/7zip/Archive/Zip/ZipIn.cpp b/CPP/7zip/Archive/Zip/ZipIn.cpp index fe5200f7..c71c40fd 100644 --- a/CPP/7zip/Archive/Zip/ZipIn.cpp +++ b/CPP/7zip/Archive/Zip/ZipIn.cpp @@ -297,11 +297,14 @@ HRESULT CInArchive::FindMarker(IInStream *stream, const UInt64 *searchLimit) if (searchLimit && *searchLimit == 0) { Byte startBuf[kMarkerSize]; - size_t processed = kMarkerSize; - RINOK(ReadStream(stream, startBuf, &processed)); - m_Position += processed; - if (processed < kMarkerSize) - return S_FALSE; + { + size_t processed = kMarkerSize; + RINOK(ReadStream(stream, startBuf, &processed)); + m_Position += processed; + if (processed != kMarkerSize) + return S_FALSE; + } + m_Signature = Get32(startBuf); if (m_Signature != NSignature::kEcd && @@ -318,7 +321,7 @@ HRESULT CInArchive::FindMarker(IInStream *stream, const UInt64 *searchLimit) size_t processed = kMarkerSize; RINOK(ReadStream(stream, startBuf, &processed)); m_Position += processed; - if (processed < kMarkerSize) + if (processed != kMarkerSize) return S_FALSE; m_Signature = Get32(startBuf); if (m_Signature != NSignature::kEcd && @@ -1567,7 +1570,7 @@ HRESULT CInArchive::ReadVols() if (Vols.StartIsZip) Vols.ZipStream = StartStream; - bool cdOK = false; + // bool cdOK = false; if (Vols.ZipStream) { @@ -1589,12 +1592,16 @@ HRESULT CInArchive::ReadVols() // Vols.EndVolIndex = ecd.ThisDisk; unsigned numMissingVols; if (cdDisk == zipDisk) - cdOK = true; + { + // cdOK = true; + } else { RINOK(ReadVols2(volCallback, cdDisk, zipDisk, zipDisk, 0, numMissingVols)); if (numMissingVols == 0) - cdOK = false; + { + // cdOK = false; + } } } else if (res != S_FALSE) diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp index 1546a2af..8cb123e6 100644 --- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp +++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp @@ -596,6 +596,7 @@ static HRESULT Update2( UInt64 numBytesToCompress = 0; unsigned i; + for (i = 0; i < updateItems.Size(); i++) { const CUpdateItem &ui = updateItems[i]; @@ -731,7 +732,6 @@ static HRESULT Update2( for (i = 0; i < updateItems.Size(); i++) refs.Refs.Add(CMemBlocks2()); - UInt32 i; for (i = 0; i < numThreads; i++) threads.Threads.Add(CThreadInfo(options2)); @@ -804,9 +804,9 @@ static HRESULT Update2( RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); } - for (UInt32 i = 0; i < numThreads; i++) + for (UInt32 k = 0; k < numThreads; k++) { - CThreadInfo &threadInfo = threads.Threads[i]; + CThreadInfo &threadInfo = threads.Threads[k]; if (threadInfo.IsFree) { threadInfo.IsFree = false; @@ -822,7 +822,7 @@ static HRESULT Update2( threadInfo.UpdateIndex = mtItemIndex - 1; compressingCompletedEvents.Add(threadInfo.CompressionCompletedEvent); - threadIndices.Add(i); + threadIndices.Add(k); break; } } @@ -927,10 +927,10 @@ static HRESULT Update2( } else { - CMemBlocks2 &memRef = refs.Refs[threadInfo.UpdateIndex]; - threadInfo.OutStreamSpec->DetachData(memRef); - memRef.CompressingResult = threadInfo.CompressingResult; - memRef.Defined = true; + CMemBlocks2 &memRef2 = refs.Refs[threadInfo.UpdateIndex]; + threadInfo.OutStreamSpec->DetachData(memRef2); + memRef2.CompressingResult = threadInfo.CompressingResult; + memRef2.Defined = true; continue; } } diff --git a/CPP/7zip/Bundles/SFXCon/SfxCon.cpp b/CPP/7zip/Bundles/SFXCon/SfxCon.cpp index 781f810c..d74f472d 100644 --- a/CPP/7zip/Bundles/SFXCon/SfxCon.cpp +++ b/CPP/7zip/Bundles/SFXCon/SfxCon.cpp @@ -363,9 +363,11 @@ int Main2( IUnknown #endif > compressCodecsInfo = codecs; - HRESULT result = codecs->Load(); - if (result != S_OK) - throw CSystemException(result); + { + HRESULT result = codecs->Load(); + if (result != S_OK) + throw CSystemException(result); + } if (command.CommandType != NCommandType::kList) { diff --git a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp index d3890235..68e28eda 100644 --- a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp +++ b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp @@ -207,11 +207,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; - HRESULT result = codecs->Load(); - if (result != S_OK) { - ShowErrorMessage(L"Can not load codecs"); - return 1; + HRESULT result = codecs->Load(); + if (result != S_OK) + { + ShowErrorMessage(L"Can not load codecs"); + return 1; + } } const FString tempDirPath = tempDir.GetPath(); diff --git a/CPP/7zip/Common/MethodProps.cpp b/CPP/7zip/Common/MethodProps.cpp index a5149ab5..09f7b29c 100644 --- a/CPP/7zip/Common/MethodProps.cpp +++ b/CPP/7zip/Common/MethodProps.cpp @@ -403,9 +403,9 @@ HRESULT CMethodProps::ParseParamsFromPROPVARIANT(const UString &realName, const if (value.vt == VT_EMPTY) { // {realName}=[empty] - UString name, value; - SplitParam(realName, name, value); - return SetParam(name, value); + UString name, valueStr; + SplitParam(realName, name, valueStr); + return SetParam(name, valueStr); } // {realName}=value diff --git a/CPP/7zip/Compress/BZip2Encoder.cpp b/CPP/7zip/Compress/BZip2Encoder.cpp index bd985dfe..e2225134 100644 --- a/CPP/7zip/Compress/BZip2Encoder.cpp +++ b/CPP/7zip/Compress/BZip2Encoder.cpp @@ -449,7 +449,7 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize) } while (++i < kGroupSize && mtfPos < mtfArraySize); - UInt32 bestPrice = 0xFFFFFFFF; + UInt32 bestPrice2 = 0xFFFFFFFF; unsigned t = 0; do { @@ -459,10 +459,10 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize) do price += lens[symbols[j]]; while (++j < i); - if (price < bestPrice) + if (price < bestPrice2) { m_Selectors[g] = (Byte)t; - bestPrice = price; + bestPrice2 = price; } } while (++t < numTables); diff --git a/CPP/7zip/Compress/Bcj2Coder.cpp b/CPP/7zip/Compress/Bcj2Coder.cpp index fd7ce7ef..96150c5f 100644 --- a/CPP/7zip/Compress/Bcj2Coder.cpp +++ b/CPP/7zip/Compress/Bcj2Coder.cpp @@ -514,13 +514,13 @@ HRESULT CDecoder::Code(ISequentialInStream * const *inStreams, const UInt64 * co STDMETHODIMP CDecoder::SetInStream2(UInt32 streamIndex, ISequentialInStream *inStream) { - inStreams[streamIndex] = inStream; + _inStreams[streamIndex] = inStream; return S_OK; } STDMETHODIMP CDecoder::ReleaseInStream2(UInt32 streamIndex) { - inStreams[streamIndex].Release(); + _inStreams[streamIndex].Release(); return S_OK; } @@ -601,7 +601,7 @@ STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize) do { UInt32 curSize = _bufsCurSizes[dec.state] - (UInt32)totalRead; - HRESULT res2 = inStreams[dec.state]->Read(_bufs[dec.state] + totalRead, curSize, &curSize); + HRESULT res2 = _inStreams[dec.state]->Read(_bufs[dec.state] + totalRead, curSize, &curSize); _readRes[dec.state] = res2; if (curSize == 0) break; diff --git a/CPP/7zip/Compress/Bcj2Coder.h b/CPP/7zip/Compress/Bcj2Coder.h index 627e505d..381b9f54 100644 --- a/CPP/7zip/Compress/Bcj2Coder.h +++ b/CPP/7zip/Compress/Bcj2Coder.h @@ -72,7 +72,7 @@ class CDecoder: unsigned _extraReadSizes[BCJ2_NUM_STREAMS]; UInt64 _inStreamsProcessed[BCJ2_NUM_STREAMS]; HRESULT _readRes[BCJ2_NUM_STREAMS]; - CMyComPtr<ISequentialInStream> inStreams[BCJ2_NUM_STREAMS]; + CMyComPtr<ISequentialInStream> _inStreams[BCJ2_NUM_STREAMS]; bool _finishMode; bool _outSizeDefined; diff --git a/CPP/7zip/Compress/DeflateEncoder.cpp b/CPP/7zip/Compress/DeflateEncoder.cpp index 94d0092b..538e7b5e 100644 --- a/CPP/7zip/Compress/DeflateEncoder.cpp +++ b/CPP/7zip/Compress/DeflateEncoder.cpp @@ -331,48 +331,50 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes) GetMatches(); - UInt32 numDistancePairs = m_MatchDistances[0]; - if (numDistancePairs == 0) - return 1; - - const UInt16 *matchDistances = m_MatchDistances + 1; - UInt32 lenMain = matchDistances[numDistancePairs - 2]; - - if (lenMain > m_NumFastBytes) + UInt32 lenEnd; { - backRes = matchDistances[numDistancePairs - 1]; - MovePos(lenMain - 1); - return lenMain; - } - m_Optimum[1].Price = m_LiteralPrices[*(Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow) - m_AdditionalOffset)]; - m_Optimum[1].PosPrev = 0; - - m_Optimum[2].Price = kIfinityPrice; - m_Optimum[2].PosPrev = 1; - + const UInt32 numDistancePairs = m_MatchDistances[0]; + if (numDistancePairs == 0) + return 1; + const UInt16 *matchDistances = m_MatchDistances + 1; + lenEnd = matchDistances[numDistancePairs - 2]; + + if (lenEnd > m_NumFastBytes) + { + backRes = matchDistances[numDistancePairs - 1]; + MovePos(lenEnd - 1); + return lenEnd; + } - UInt32 offs = 0; - for (UInt32 i = kMatchMinLen; i <= lenMain; i++) - { - UInt32 distance = matchDistances[offs + 1]; - m_Optimum[i].PosPrev = 0; - m_Optimum[i].BackPrev = (UInt16)distance; - m_Optimum[i].Price = m_LenPrices[i - kMatchMinLen] + m_PosPrices[GetPosSlot(distance)]; - if (i == matchDistances[offs]) - offs += 2; + m_Optimum[1].Price = m_LiteralPrices[*(Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow) - m_AdditionalOffset)]; + m_Optimum[1].PosPrev = 0; + + m_Optimum[2].Price = kIfinityPrice; + m_Optimum[2].PosPrev = 1; + + UInt32 offs = 0; + + for (UInt32 i = kMatchMinLen; i <= lenEnd; i++) + { + UInt32 distance = matchDistances[offs + 1]; + m_Optimum[i].PosPrev = 0; + m_Optimum[i].BackPrev = (UInt16)distance; + m_Optimum[i].Price = m_LenPrices[i - kMatchMinLen] + m_PosPrices[GetPosSlot(distance)]; + if (i == matchDistances[offs]) + offs += 2; + } } UInt32 cur = 0; - UInt32 lenEnd = lenMain; + for (;;) { ++cur; if (cur == lenEnd || cur == kNumOptsBase || m_Pos >= kMatchArrayLimit) return Backward(backRes, cur); GetMatches(); - matchDistances = m_MatchDistances + 1; - - UInt32 numDistancePairs = m_MatchDistances[0]; + const UInt16 *matchDistances = m_MatchDistances + 1; + const UInt32 numDistancePairs = m_MatchDistances[0]; UInt32 newLen = 0; if (numDistancePairs != 0) { @@ -388,18 +390,20 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes) } } UInt32 curPrice = m_Optimum[cur].Price; - UInt32 curAnd1Price = curPrice + m_LiteralPrices[*(Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow) + cur - m_AdditionalOffset)]; - COptimal &optimum = m_Optimum[cur + 1]; - if (curAnd1Price < optimum.Price) { - optimum.Price = curAnd1Price; - optimum.PosPrev = (UInt16)cur; + const UInt32 curAnd1Price = curPrice + m_LiteralPrices[*(Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow) + cur - m_AdditionalOffset)]; + COptimal &optimum = m_Optimum[cur + 1]; + if (curAnd1Price < optimum.Price) + { + optimum.Price = curAnd1Price; + optimum.PosPrev = (UInt16)cur; + } } if (numDistancePairs == 0) continue; while (lenEnd < cur + newLen) m_Optimum[++lenEnd].Price = kIfinityPrice; - offs = 0; + UInt32 offs = 0; UInt32 distance = matchDistances[offs + 1]; curPrice += m_PosPrices[GetPosSlot(distance)]; for (UInt32 lenTest = kMatchMinLen; ; lenTest++) diff --git a/CPP/7zip/Compress/LzmsDecoder.cpp b/CPP/7zip/Compress/LzmsDecoder.cpp index 1f83b63d..0e823446 100644 --- a/CPP/7zip/Compress/LzmsDecoder.cpp +++ b/CPP/7zip/Compress/LzmsDecoder.cpp @@ -267,12 +267,15 @@ HRESULT CDecoder::CodeReal(const Byte *in, size_t inSize, Byte *_win, size_t out { { - unsigned i; - for (i = 0 ; i < k_NumReps + 1; i++) - _reps[i] = i + 1; + { + for (unsigned i = 0 ; i < k_NumReps + 1; i++) + _reps[i] = i + 1; + } - for (i = 0 ; i < k_NumReps + 1; i++) - _deltaReps[i] = i + 1; + { + for (unsigned i = 0 ; i < k_NumReps + 1; i++) + _deltaReps[i] = i + 1; + } mainState = 0; matchState = 0; diff --git a/CPP/7zip/Compress/LzxDecoder.h b/CPP/7zip/Compress/LzxDecoder.h index b06d5948..a5c6f12c 100644 --- a/CPP/7zip/Compress/LzxDecoder.h +++ b/CPP/7zip/Compress/LzxDecoder.h @@ -67,19 +67,21 @@ public: { if (_bitPos <= 16) { - UInt32 val; - if (_buf >= _bufLim) - { - val = 0xFFFF; - _extraSize += 2; - } - else { - val = GetUi16(_buf); - _buf += 2; + UInt32 val; + if (_buf >= _bufLim) + { + val = 0xFFFF; + _extraSize += 2; + } + else + { + val = GetUi16(_buf); + _buf += 2; + } + _value = (_value << 16) | val; + _bitPos += 16; } - _value = (_value << 16) | val; - _bitPos += 16; if (_bitPos <= 16) { UInt32 val; diff --git a/CPP/7zip/Compress/Rar3Decoder.cpp b/CPP/7zip/Compress/Rar3Decoder.cpp index 832eb112..3bf25132 100644 --- a/CPP/7zip/Compress/Rar3Decoder.cpp +++ b/CPP/7zip/Compress/Rar3Decoder.cpp @@ -204,9 +204,9 @@ HRESULT CDecoder::WriteBuf() { for (unsigned j = i; j < _tempFilters.Size(); j++) { - CTempFilter *filter = _tempFilters[j]; - if (filter && filter->NextWindow) - filter->NextWindow = false; + CTempFilter *filter2 = _tempFilters[j]; + if (filter2 && filter2->NextWindow) + filter2->NextWindow = false; } _wrPtr = writtenBorder; return S_OK; // check it @@ -270,15 +270,16 @@ bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize) filter->ExecCount++; } - int numEmptyItems = 0; - unsigned i; - for (i = 0; i < _tempFilters.Size(); i++) + unsigned numEmptyItems = 0; { - _tempFilters[i - numEmptyItems] = _tempFilters[i]; - if (!_tempFilters[i]) - numEmptyItems++; - if (numEmptyItems > 0) - _tempFilters[i] = NULL; + FOR_VECTOR (i, _tempFilters) + { + _tempFilters[i - numEmptyItems] = _tempFilters[i]; + if (!_tempFilters[i]) + numEmptyItems++; + if (numEmptyItems != 0) + _tempFilters[i] = NULL; + } } if (numEmptyItems == 0) { @@ -305,7 +306,7 @@ bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize) if (firstByte & 0x10) { UInt32 initMask = inp.ReadBits(NVm::kNumGpRegs); - for (int i = 0; i < NVm::kNumGpRegs; i++) + for (unsigned i = 0; i < NVm::kNumGpRegs; i++) if (initMask & (1 << i)) tempFilter->InitR[i] = inp.ReadEncodedUInt32(); } @@ -321,12 +322,14 @@ bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize) isOK = filter->PrepareProgram(_vmCode, vmCodeSize); } - Byte *globalData = &tempFilter->GlobalData[0]; - for (i = 0; i < NVm::kNumGpRegs; i++) - NVm::SetValue32(&globalData[i * 4], tempFilter->InitR[i]); - NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockSize], tempFilter->BlockSize); - NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockPos], 0); // It was commented. why? - NVm::SetValue32(&globalData[NVm::NGlobalOffset::kExecCount], filter->ExecCount); + { + Byte *globalData = &tempFilter->GlobalData[0]; + for (unsigned i = 0; i < NVm::kNumGpRegs; i++) + NVm::SetValue32(&globalData[i * 4], tempFilter->InitR[i]); + NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockSize], tempFilter->BlockSize); + NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockPos], 0); // It was commented. why? + NVm::SetValue32(&globalData[NVm::NGlobalOffset::kExecCount], filter->ExecCount); + } if (firstByte & 8) { @@ -497,24 +500,24 @@ HRESULT CDecoder::DecodePPM(Int32 num, bool &keepDecompressing) { for (int i = 0; i < 3; i++) { - int c = DecodePpmSymbol(); - if (c < 0) + int c2 = DecodePpmSymbol(); + if (c2 < 0) { PpmError = true; return S_FALSE; } - distance = (distance << 8) + (Byte)c; + distance = (distance << 8) + (Byte)c2; } distance++; length += 28; } - int c = DecodePpmSymbol(); - if (c < 0) + int c2 = DecodePpmSymbol(); + if (c2 < 0) { PpmError = true; return S_FALSE; } - length += c; + length += c2; if (distance >= _lzSize) return S_FALSE; CopyBlock(distance, length); @@ -733,10 +736,10 @@ HRESULT CDecoder::DecodeLZ(bool &keepDecompressing) rep0 = distance; } - UInt32 sym = m_LenDecoder.Decode(&m_InBitStream.BitDecoder); - if (sym >= kLenTableSize) + const UInt32 sym2 = m_LenDecoder.Decode(&m_InBitStream.BitDecoder); + if (sym2 >= kLenTableSize) return S_FALSE; - length = 2 + kLenStart[sym] + m_InBitStream.BitDecoder.ReadBits(kLenDirectBits[sym]); + length = 2 + kLenStart[sym2] + m_InBitStream.BitDecoder.ReadBits(kLenDirectBits[sym2]); } else { @@ -753,12 +756,12 @@ HRESULT CDecoder::DecodeLZ(bool &keepDecompressing) { sym -= 271; length = kNormalMatchMinLen + (UInt32)kLenStart[sym] + m_InBitStream.BitDecoder.ReadBits(kLenDirectBits[sym]); - UInt32 sym = m_DistDecoder.Decode(&m_InBitStream.BitDecoder); - if (sym >= kDistTableSize) + const UInt32 sym2 = m_DistDecoder.Decode(&m_InBitStream.BitDecoder); + if (sym2 >= kDistTableSize) return S_FALSE; - rep0 = kDistStart[sym]; - int numBits = kDistDirectBits[sym]; - if (sym >= (kNumAlignBits * 2) + 2) + rep0 = kDistStart[sym2]; + int numBits = kDistDirectBits[sym2]; + if (sym2 >= (kNumAlignBits * 2) + 2) { if (numBits > kNumAlignBits) rep0 += (m_InBitStream.BitDecoder.ReadBits(numBits - kNumAlignBits) << kNumAlignBits); @@ -769,13 +772,13 @@ HRESULT CDecoder::DecodeLZ(bool &keepDecompressing) } else { - UInt32 sym = m_AlignDecoder.Decode(&m_InBitStream.BitDecoder); - if (sym < (1 << kNumAlignBits)) + const UInt32 sym3 = m_AlignDecoder.Decode(&m_InBitStream.BitDecoder); + if (sym3 < (1 << kNumAlignBits)) { - rep0 += sym; - PrevAlignBits = sym; + rep0 += sym3; + PrevAlignBits = sym3; } - else if (sym == (1 << kNumAlignBits)) + else if (sym3 == (1 << kNumAlignBits)) { PrevAlignCount = kNumAlignReps; rep0 += PrevAlignBits; diff --git a/CPP/7zip/Compress/Rar5Decoder.cpp b/CPP/7zip/Compress/Rar5Decoder.cpp index 627f7ee6..dc8830f8 100644 --- a/CPP/7zip/Compress/Rar5Decoder.cpp +++ b/CPP/7zip/Compress/Rar5Decoder.cpp @@ -639,10 +639,10 @@ HRESULT CDecoder::DecodeLZ() rep0 = dist; } - UInt32 sym = m_LenDecoder.Decode(&_bitStream); - if (sym >= kLenTableSize) + const UInt32 sym2 = m_LenDecoder.Decode(&_bitStream); + if (sym2 >= kLenTableSize) break; // return S_FALSE; - len = SlotToLen(_bitStream, sym); + len = SlotToLen(_bitStream, sym2); } else { diff --git a/CPP/7zip/Crypto/ZipCrypto.cpp b/CPP/7zip/Crypto/ZipCrypto.cpp index 77aff83b..ae715063 100644 --- a/CPP/7zip/Crypto/ZipCrypto.cpp +++ b/CPP/7zip/Crypto/ZipCrypto.cpp @@ -13,25 +13,25 @@ namespace NCrypto { namespace NZip { #define UPDATE_KEYS(b) { \ - Key0 = CRC_UPDATE_BYTE(Key0, b); \ - Key1 = (Key1 + (Key0 & 0xFF)) * 0x8088405 + 1; \ - Key2 = CRC_UPDATE_BYTE(Key2, (Byte)(Key1 >> 24)); } \ + key0 = CRC_UPDATE_BYTE(key0, b); \ + key1 = (key1 + (key0 & 0xFF)) * 0x8088405 + 1; \ + key2 = CRC_UPDATE_BYTE(key2, (Byte)(key1 >> 24)); } \ -#define DECRYPT_BYTE_1 UInt32 temp = Key2 | 2; +#define DECRYPT_BYTE_1 UInt32 temp = key2 | 2; #define DECRYPT_BYTE_2 ((Byte)((temp * (temp ^ 1)) >> 8)) STDMETHODIMP CCipher::CryptoSetPassword(const Byte *data, UInt32 size) { - UInt32 Key0 = 0x12345678; - UInt32 Key1 = 0x23456789; - UInt32 Key2 = 0x34567890; + UInt32 key0 = 0x12345678; + UInt32 key1 = 0x23456789; + UInt32 key2 = 0x34567890; for (UInt32 i = 0; i < size; i++) UPDATE_KEYS(data[i]); - KeyMem0 = Key0; - KeyMem1 = Key1; - KeyMem2 = Key2; + KeyMem0 = key0; + KeyMem1 = key1; + KeyMem2 = key2; return S_OK; } @@ -60,9 +60,9 @@ HRESULT CEncoder::WriteHeader_Check16(ISequentialOutStream *outStream, UInt16 cr STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size) { - UInt32 Key0 = this->Key0; - UInt32 Key1 = this->Key1; - UInt32 Key2 = this->Key2; + UInt32 key0 = this->Key0; + UInt32 key1 = this->Key1; + UInt32 key2 = this->Key2; for (UInt32 i = 0; i < size; i++) { @@ -72,9 +72,9 @@ STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size) UPDATE_KEYS(b); } - this->Key0 = Key0; - this->Key1 = Key1; - this->Key2 = Key2; + this->Key0 = key0; + this->Key1 = key1; + this->Key2 = key2; return size; } @@ -92,9 +92,9 @@ void CDecoder::Init_BeforeDecode() STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) { - UInt32 Key0 = this->Key0; - UInt32 Key1 = this->Key1; - UInt32 Key2 = this->Key2; + UInt32 key0 = this->Key0; + UInt32 key1 = this->Key1; + UInt32 key2 = this->Key2; for (UInt32 i = 0; i < size; i++) { @@ -104,9 +104,9 @@ STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) data[i] = b; } - this->Key0 = Key0; - this->Key1 = Key1; - this->Key2 = Key2; + this->Key0 = key0; + this->Key1 = key1; + this->Key2 = key2; return size; } diff --git a/CPP/7zip/Crypto/ZipStrong.cpp b/CPP/7zip/Crypto/ZipStrong.cpp index d70e1ba1..6d73a34b 100644 --- a/CPP/7zip/Crypto/ZipStrong.cpp +++ b/CPP/7zip/Crypto/ZipStrong.cpp @@ -139,7 +139,6 @@ HRESULT CDecoder::Init_and_CheckPassword(bool &passwOK) if (cert) { // how to filter rd, if ((rdSize & 0xF) != 0) ? - /* if ((rdSize & 0x7) != 0) return E_NOTIMPL; } diff --git a/CPP/7zip/UI/Agent/Agent.cpp b/CPP/7zip/UI/Agent/Agent.cpp index 201e82c1..a9021ef9 100644 --- a/CPP/7zip/UI/Agent/Agent.cpp +++ b/CPP/7zip/UI/Agent/Agent.cpp @@ -1067,10 +1067,7 @@ STDMETHODIMP CAgentFolder::BindToParentFolder(IFolderFolder **resultFolder) if (parentIndex < 0) proxyDirIndex = k_Proxy2_RootDirIndex; else - { - const CProxyFile2 &file = _proxy2->Files[parentIndex]; - proxyDirIndex = file.DirIndex; - } + proxyDirIndex = _proxy2->Files[parentIndex].DirIndex; } } else diff --git a/CPP/7zip/UI/Agent/AgentProxy.cpp b/CPP/7zip/UI/Agent/AgentProxy.cpp index 4c0dbc77..eb07efd8 100644 --- a/CPP/7zip/UI/Agent/AgentProxy.cpp +++ b/CPP/7zip/UI/Agent/AgentProxy.cpp @@ -34,10 +34,10 @@ int CProxyArc::FindSubDir(unsigned dirIndex, const wchar_t *name, unsigned &inse return -1; } unsigned mid = (left + right) / 2; - unsigned dirIndex = subDirs[mid]; - int compare = CompareFileNames(name, Dirs[dirIndex].Name); + unsigned dirIndex2 = subDirs[mid]; + int compare = CompareFileNames(name, Dirs[dirIndex2].Name); if (compare == 0) - return dirIndex; + return dirIndex2; if (compare < 0) right = mid; else diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp index 62da5e9f..bc116c93 100644 --- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp +++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp @@ -1046,8 +1046,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode) if (_item.IsAltStream && _item.ParentIndex != (UInt32)(Int32)-1) { - CIndexToPathPair pair(_item.ParentIndex); - int renIndex = _renamedFiles.FindInSorted(pair); + int renIndex = _renamedFiles.FindInSorted(CIndexToPathPair(_item.ParentIndex)); if (renIndex >= 0) { const CIndexToPathPair &pair = _renamedFiles[renIndex]; @@ -1319,7 +1318,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode) if (needWriteFile) { _outFileStreamSpec = new COutFileStream; - CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec); + CMyComPtr<ISequentialOutStream> outStreamLoc2(_outFileStreamSpec); if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS)) { // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit) @@ -1346,7 +1345,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode) RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL)); } - _outFileStream = outStreamLoc; + _outFileStream = outStreamLoc2; } } } diff --git a/CPP/7zip/UI/Common/Bench.cpp b/CPP/7zip/UI/Common/Bench.cpp index fb69b544..255c8273 100644 --- a/CPP/7zip/UI/Common/Bench.cpp +++ b/CPP/7zip/UI/Common/Bench.cpp @@ -866,11 +866,10 @@ HRESULT CEncoderInfo::Init( outStreamSpec = new CBenchmarkOutStream; + outStream = outStreamSpec; if (!outStreamSpec->Alloc(kCompressedBufferSize)) return E_OUTOFMEMORY; - outStream = outStreamSpec; - propStreamSpec = 0; if (!propStream) { @@ -917,15 +916,8 @@ HRESULT CEncoderInfo::Init( // we must call encoding one time to calculate password key for key cache. // it must be after WriteCoderProperties! - CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream; - CMyComPtr<ISequentialInStream> inStream = inStreamSpec; Byte temp[16]; memset(temp, 0, sizeof(temp)); - inStreamSpec->Init(temp, sizeof(temp)); - - CCrcOutStream *outStreamSpec = new CCrcOutStream; - CMyComPtr<ISequentialOutStream> outStream = outStreamSpec; - outStreamSpec->Init(); if (_encoderFilter) { @@ -934,7 +926,15 @@ HRESULT CEncoderInfo::Init( } else { - RINOK(_encoder->Code(inStream, outStream, 0, 0, NULL)); + CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream; + CMyComPtr<ISequentialInStream> inStream = inStreamSpec; + inStreamSpec->Init(temp, sizeof(temp)); + + CCrcOutStream *crcStreamSpec = new CCrcOutStream; + CMyComPtr<ISequentialOutStream> crcStream = crcStreamSpec; + crcStreamSpec->Init(); + + RINOK(_encoder->Code(inStream, crcStream, 0, 0, NULL)); } } } @@ -2390,10 +2390,10 @@ static void x86cpuid_to_String(const Cx86cpuid &c, AString &s) { for (int i = 0; i < 3; i++) { - UInt32 c[4] = { 0 }; - MyCPUID(0x80000002 + i, &c[0], &c[1], &c[2], &c[3]); + UInt32 d[4] = { 0 }; + MyCPUID(0x80000002 + i, &d[0], &d[1], &d[2], &d[3]); for (int j = 0; j < 4; j++) - PrintCpuChars(s, c[j]); + PrintCpuChars(s, d[j]); } } @@ -2469,10 +2469,11 @@ HRESULT Bench( bool multiThreadTests = false; COneMethodInfo method; - unsigned i; CBenchBuffer fileDataBuffer; - + + { + unsigned i; for (i = 0; i < props.Size(); i++) { const CProperty &property = props[i]; @@ -2568,6 +2569,7 @@ HRESULT Bench( RINOK(method.ParseMethodFromPROPVARIANT(name, propVariant)); } + } if (printCallback) { @@ -3013,7 +3015,7 @@ HRESULT Bench( if (needSetComplexity) callback.BenchProps.SetLzmaCompexity(); - for (i = 0; i < numIterations; i++) + for (unsigned i = 0; i < numIterations; i++) { const unsigned kStartDicLog = 22; unsigned pow = (dict < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog; diff --git a/CPP/7zip/UI/Common/Extract.cpp b/CPP/7zip/UI/Common/Extract.cpp index 14aa7407..a6de8dc0 100644 --- a/CPP/7zip/UI/Common/Extract.cpp +++ b/CPP/7zip/UI/Common/Extract.cpp @@ -375,10 +375,10 @@ HRESULT Extract( thereAreNotOpenArcs = true; if (!options.StdInMode) { - NFind::CFileInfo fi; - if (fi.Find(us2fs(arcPath))) - if (!fi.IsDir()) - totalPackProcessed += fi.Size; + NFind::CFileInfo fi2; + if (fi2.Find(us2fs(arcPath))) + if (!fi2.IsDir()) + totalPackProcessed += fi2.Size; } continue; } diff --git a/CPP/7zip/UI/Common/HashCalc.cpp b/CPP/7zip/UI/Common/HashCalc.cpp index c33f837f..60a747d5 100644 --- a/CPP/7zip/UI/Common/HashCalc.cpp +++ b/CPP/7zip/UI/Common/HashCalc.cpp @@ -101,8 +101,8 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto h.Hasher = hasher; h.Name = name; h.DigestSize = digestSize; - for (unsigned i = 0; i < k_HashCalc_NumGroups; i++) - memset(h.Digests[i], 0, digestSize); + for (unsigned k = 0; k < k_HashCalc_NumGroups; k++) + memset(h.Digests[k], 0, digestSize); } return S_OK; diff --git a/CPP/7zip/UI/Common/OpenArchive.cpp b/CPP/7zip/UI/Common/OpenArchive.cpp index 4081b0a6..49da1c97 100644 --- a/CPP/7zip/UI/Common/OpenArchive.cpp +++ b/CPP/7zip/UI/Common/OpenArchive.cpp @@ -582,9 +582,9 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa if (prevWasAltStream) { { - UString &s = parts[parts.Size() - 2]; - s += L':'; - s += parts.Back(); + UString &s2 = parts[parts.Size() - 2]; + s2 += L':'; + s2 += parts.Back(); } parts.DeleteBack(); } @@ -2015,7 +2015,6 @@ HRESULT CArc::OpenStream2(const COpenOptions &op) const CArcInfoEx &ai = op.codecs->Formats[formatIndex]; if (ai.FindExtension(extension) >= 0) { - const CArcInfoEx &ai = op.codecs->Formats[formatIndex]; if (ai.Flags_FindSignature() && searchMarkerInHandler) return S_FALSE; } @@ -3467,6 +3466,8 @@ static bool ParseTypeParams(const UString &s, COpenType &type) bool ParseType(CCodecs &codecs, const UString &s, COpenType &type) { int pos2 = s.Find(L':'); + + { UString name; if (pos2 < 0) { @@ -3501,13 +3502,15 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type) } type.FormatIndex = index; + + } for (unsigned i = pos2; i < s.Len();) { int next = s.Find(L':', i); if (next < 0) next = s.Len(); - UString name = s.Mid(i, next - i); + const UString name = s.Mid(i, next - i); if (name.IsEmpty()) return false; if (!ParseTypeParams(name, type)) diff --git a/CPP/7zip/UI/Common/Update.cpp b/CPP/7zip/UI/Common/Update.cpp index 2dfb2104..69fdb78e 100644 --- a/CPP/7zip/UI/Common/Update.cpp +++ b/CPP/7zip/UI/Common/Update.cpp @@ -758,15 +758,15 @@ static HRESULT Compress( return errorInfo.SetFromLastError("cannot open SFX module", options.SfxModule); CMyComPtr<ISequentialOutStream> sfxOutStream; - COutFileStream *outStreamSpec = NULL; + COutFileStream *outStreamSpec2 = NULL; if (options.VolumesSizes.Size() == 0) sfxOutStream = outStream; else { - outStreamSpec = new COutFileStream; - sfxOutStream = outStreamSpec; + outStreamSpec2 = new COutFileStream; + sfxOutStream = outStreamSpec2; FString realPath = us2fs(archivePath.GetFinalPath()); - if (!outStreamSpec->Create(realPath, false)) + if (!outStreamSpec2->Create(realPath, false)) return errorInfo.SetFromLastError("cannot open file", realPath); } @@ -778,9 +778,9 @@ static HRESULT Compress( RINOK(NCompress::CopyStream(sfxStream, sfxOutStream, NULL)); - if (outStreamSpec) + if (outStreamSpec2) { - RINOK(outStreamSpec->Close()); + RINOK(outStreamSpec2->Close()); } } @@ -1060,7 +1060,7 @@ HRESULT UpdateArchive( !options.SetArcPath(codecs, cmdArcPath2)) return E_NOTIMPL; } - UString arcPath = options.ArchivePath.GetFinalPath(); + const UString arcPath = options.ArchivePath.GetFinalPath(); if (cmdArcPath2.IsEmpty()) { @@ -1088,10 +1088,10 @@ HRESULT UpdateArchive( return E_NOTIMPL; if (options.VolumesSizes.Size() > 0) return E_NOTIMPL; - CObjectVector<COpenType> types; + CObjectVector<COpenType> types2; // change it. if (options.MethodMode.Type_Defined) - types.Add(options.MethodMode.Type); + types2.Add(options.MethodMode.Type); // We need to set Properties to open archive only in some cases (WIM archives). CIntVector excl; @@ -1100,7 +1100,7 @@ HRESULT UpdateArchive( op.props = &options.MethodMode.Properties; #endif op.codecs = codecs; - op.types = &types; + op.types = &types2; op.excludedFormats = ! op.stdInMode = false; op.stream = NULL; @@ -1289,10 +1289,11 @@ HRESULT UpdateArchive( } } - unsigned i; - for (i = 0; i < options.Commands.Size(); i++) + unsigned ci; + + for (ci = 0; ci < options.Commands.Size(); ci++) { - CArchivePath &ap = options.Commands[i].ArchivePath; + CArchivePath &ap = options.Commands[ci].ArchivePath; if (usesTempDir) { // Check it @@ -1301,7 +1302,7 @@ HRESULT UpdateArchive( // ap.TempPrefix = tempDirPrefix; } if (!options.StdOutMode && - (i > 0 || !createTempFile)) + (ci > 0 || !createTempFile)) { const FString path = us2fs(ap.GetFinalPath()); if (NFind::DoesFileOrDirExist(path)) @@ -1334,7 +1335,7 @@ HRESULT UpdateArchive( { unsigned num = dirItems.Items.Size(); processedItems.Alloc(num); - for (i = 0; i < num; i++) + for (unsigned i = 0; i < num; i++) processedItems[i] = 0; } @@ -1348,10 +1349,10 @@ HRESULT UpdateArchive( #endif */ - for (i = 0; i < options.Commands.Size(); i++) + for (ci = 0; ci < options.Commands.Size(); ci++) { const CArc *arc = thereIsInArchive ? arcLink.GetArc() : NULL; - CUpdateArchiveCommand &command = options.Commands[i]; + CUpdateArchiveCommand &command = options.Commands[ci]; UString name; bool isUpdating; @@ -1363,7 +1364,7 @@ HRESULT UpdateArchive( else { name = command.ArchivePath.GetFinalPath(); - isUpdating = (i == 0 && options.UpdateArchiveItself && thereIsInArchive); + isUpdating = (ci == 0 && options.UpdateArchiveItself && thereIsInArchive); } RINOK(callback->StartArchive(name, isUpdating)) @@ -1455,19 +1456,19 @@ HRESULT UpdateArchive( { CArchivePath &ap = options.Commands[i].ArchivePath; FString finalPath = us2fs(ap.GetFinalPath()); - FString arcPath; - if (!MyGetFullPathName(finalPath, arcPath)) + FString arcPath2; + if (!MyGetFullPathName(finalPath, arcPath2)) return errorInfo.SetFromLastError("GetFullPathName error", finalPath); - fullPaths.Add(arcPath); + fullPaths.Add(arcPath2); } CCurrentDirRestorer curDirRestorer; for (i = 0; i < fullPaths.Size(); i++) { - UString arcPath = fs2us(fullPaths[i]); - UString fileName = ExtractFileNameFromPath(arcPath); - AString path = GetAnsiString(arcPath); + UString arcPath2 = fs2us(fullPaths[i]); + UString fileName = ExtractFileNameFromPath(arcPath2); + AString path = GetAnsiString(arcPath2); AString name = GetAnsiString(fileName); // Warning!!! MAPISendDocuments function changes Current directory // fnSend(0, ";", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0); @@ -1505,6 +1506,8 @@ HRESULT UpdateArchive( CRecordVector<CRefSortPair> pairs; FStringVector foldersNames; + unsigned i; + for (i = 0; i < dirItems.Items.Size(); i++) { const CDirItem &dirItem = dirItems.Items[i]; diff --git a/CPP/7zip/UI/Common/UpdateCallback.cpp b/CPP/7zip/UI/Common/UpdateCallback.cpp index 6c439cfd..5499f2a1 100644 --- a/CPP/7zip/UI/Common/UpdateCallback.cpp +++ b/CPP/7zip/UI/Common/UpdateCallback.cpp @@ -219,9 +219,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, con return Arc->GetRawProps->GetRawProp( ArcItems ? (*ArcItems)[up.ArcIndex].IndexInServer : up.ArcIndex, propID, data, dataSize, propType); - { - const CUpdatePair2 &up = (*UpdatePairs)[index]; /* if (!up.NewData) return E_FAIL; diff --git a/CPP/7zip/UI/Console/ConsoleClose.cpp b/CPP/7zip/UI/Console/ConsoleClose.cpp index 73498188..703f8213 100644 --- a/CPP/7zip/UI/Console/ConsoleClose.cpp +++ b/CPP/7zip/UI/Console/ConsoleClose.cpp @@ -59,7 +59,10 @@ CCtrlHandlerSetter::~CCtrlHandlerSetter() { #if !defined(UNDER_CE) && defined(_WIN32) if (!SetConsoleCtrlHandler(HandlerRoutine, FALSE)) - throw "SetConsoleCtrlHandler fails"; + { + // warning for throw in destructor. + // throw "SetConsoleCtrlHandler fails"; + } #endif } diff --git a/CPP/7zip/UI/Console/List.cpp b/CPP/7zip/UI/Console/List.cpp index e70f1b67..362c1ff1 100644 --- a/CPP/7zip/UI/Console/List.cpp +++ b/CPP/7zip/UI/Console/List.cpp @@ -900,10 +900,10 @@ HRESULT Print_OpenArchive_Props(CStdOutStream &so, const CCodecs *codecs, const RINOK(PrintArcProp(so, archive, kpidPhySize, NULL)); if (er.TailSize != 0) PrintPropNameAndNumber(so, kpidTailSize, er.TailSize); - UInt32 numProps; - RINOK(archive->GetNumberOfArchiveProperties(&numProps)); - { + UInt32 numProps; + RINOK(archive->GetNumberOfArchiveProperties(&numProps)); + for (UInt32 j = 0; j < numProps; j++) { CMyComBSTR name; diff --git a/CPP/7zip/UI/Explorer/RegistryContextMenu.cpp b/CPP/7zip/UI/Explorer/RegistryContextMenu.cpp index d0c9189d..d83aa76e 100644 --- a/CPP/7zip/UI/Explorer/RegistryContextMenu.cpp +++ b/CPP/7zip/UI/Explorer/RegistryContextMenu.cpp @@ -157,10 +157,12 @@ LONG SetContextMenuHandler(bool setMode, const UString &path, UInt32 wow) INIT_REG_WOW + LONG res; + + { CSysString s = TEXT("CLSID\\"); s += k_Clsid; - LONG res; if (setMode) { { @@ -193,6 +195,7 @@ LONG SetContextMenuHandler(bool setMode, const UString &path, UInt32 wow) MyRegistry_DeleteKey_HKCR(s2, wow); res = MyRegistry_DeleteKey_HKCR(s, wow); } + } // shellex items probably are shared beween 32-bit and 64-bit apps. So we don't delete items for delete operation. if (setMode) diff --git a/CPP/7zip/UI/Far/Far.cpp b/CPP/7zip/UI/Far/Far.cpp index 6505c6c4..789cc223 100644 --- a/CPP/7zip/UI/Far/Far.cpp +++ b/CPP/7zip/UI/Far/Far.cpp @@ -508,10 +508,10 @@ EXTERN_C HANDLE WINAPI OpenPlugin(int openFrom, INT_PTR item) EXTERN_C void WINAPI ClosePlugin(HANDLE plugin) { // OutputDebugStringA("-- ClosePlugin --- START"); - MY_TRY_BEGIN; + // MY_TRY_BEGIN; delete (CPlugin *)plugin; // OutputDebugStringA("-- ClosePlugin --- END"); - MY_TRY_END1("ClosePlugin"); + // MY_TRY_END1("ClosePlugin"); } EXTERN_C int WINAPI GetFindData(HANDLE plugin, struct PluginPanelItem **panelItems, int *itemsNumber, int opMode) diff --git a/CPP/7zip/UI/Far/Plugin.cpp b/CPP/7zip/UI/Far/Plugin.cpp index 485358d3..607cdfe3 100644 --- a/CPP/7zip/UI/Far/Plugin.cpp +++ b/CPP/7zip/UI/Far/Plugin.cpp @@ -496,6 +496,7 @@ void CPlugin::GetOpenPluginInfo(struct OpenPluginInfo *info) info->Format = kPluginFormatName; + { UString name; { FString dirPrefix, fileName; @@ -517,6 +518,8 @@ void CPlugin::GetOpenPluginInfo(struct OpenPluginInfo *info) COPY_STR_LIMITED(m_PannelTitleBuffer, UnicodeStringToMultiByte(m_PannelTitle, CP_OEMCP)); info->PanelTitle = m_PannelTitleBuffer; + } + memset(m_InfoLines, 0, sizeof(m_InfoLines)); m_InfoLines[0].Text[0] = 0; m_InfoLines[0].Separator = TRUE; @@ -716,11 +719,14 @@ HRESULT CPlugin::ShowAttributesWindow() int size = 2; CRecordVector<CInitDialogItem> initDialogItems; - + int xSize = 70; - CInitDialogItem idi = - { DI_DOUBLEBOX, 3, 1, xSize - 4, size - 2, false, false, 0, false, NMessageID::kProperties, NULL, NULL }; - initDialogItems.Add(idi); + { + const CInitDialogItem idi = + { DI_DOUBLEBOX, 3, 1, xSize - 4, size - 2, false, false, 0, false, NMessageID::kProperties, NULL, NULL }; + initDialogItems.Add(idi); + } + AStringVector values; const int kStartY = 3; @@ -731,12 +737,14 @@ HRESULT CPlugin::ShowAttributesWindow() int startY = kStartY + values.Size(); - CInitDialogItem idi = - { DI_TEXT, 5, startY, 0, 0, false, false, 0, false, 0, NULL, NULL }; - idi.DataMessageId = FindPropNameID(property.ID); - if (idi.DataMessageId < 0) - idi.DataString = property.Name; - initDialogItems.Add(idi); + { + CInitDialogItem idi = + { DI_TEXT, 5, startY, 0, 0, false, false, 0, false, 0, NULL, NULL }; + idi.DataMessageId = FindPropNameID(property.ID); + if (idi.DataMessageId < 0) + idi.DataString = property.Name; + initDialogItems.Add(idi); + } NCOM::CPropVariant prop; RINOK(_folder->GetProperty(itemIndex, property.ID, &prop)); @@ -744,7 +752,7 @@ HRESULT CPlugin::ShowAttributesWindow() values.Add(s); { - CInitDialogItem idi = + const CInitDialogItem idi = { DI_TEXT, 30, startY, 0, 0, false, false, 0, false, -1, NULL, NULL }; initDialogItems.Add(idi); } @@ -774,7 +782,7 @@ HRESULT CPlugin::ShowAttributesWindow() properties2.Add(prop); } - for (unsigned i = 0; i < properties2.Size(); i++) + for (i = 0; i < properties2.Size(); i++) { const CArchiveItemProperty &property = properties2[i]; CMyComBSTR name; @@ -802,9 +810,9 @@ HRESULT CPlugin::ShowAttributesWindow() } else { - for (UInt32 i = 0; i < dataSize; i++) + for (UInt32 k = 0; k < dataSize; k++) { - Byte b = ((const Byte *)data)[i]; + Byte b = ((const Byte *)data)[k]; s += GetHex((Byte)((b >> 4) & 0xF)); s += GetHex((Byte)(b & 0xF)); } @@ -812,17 +820,20 @@ HRESULT CPlugin::ShowAttributesWindow() } int startY = kStartY + values.Size(); - CInitDialogItem idi = - { DI_TEXT, 5, startY, 0, 0, false, false, 0, false, 0, NULL, NULL }; - idi.DataMessageId = FindPropNameID(property.ID); - if (idi.DataMessageId < 0) - idi.DataString = property.Name; - initDialogItems.Add(idi); + + { + CInitDialogItem idi = + { DI_TEXT, 5, startY, 0, 0, false, false, 0, false, 0, NULL, NULL }; + idi.DataMessageId = FindPropNameID(property.ID); + if (idi.DataMessageId < 0) + idi.DataString = property.Name; + initDialogItems.Add(idi); + } values.Add(s); { - CInitDialogItem idi = + const CInitDialogItem idi = { DI_TEXT, 30, startY, 0, 0, false, false, 0, false, -1, NULL, NULL }; initDialogItems.Add(idi); } diff --git a/CPP/7zip/UI/Far/PluginWrite.cpp b/CPP/7zip/UI/Far/PluginWrite.cpp index 8afba039..b22577af 100644 --- a/CPP/7zip/UI/Far/PluginWrite.cpp +++ b/CPP/7zip/UI/Far/PluginWrite.cpp @@ -437,10 +437,8 @@ HRESULT CompressFiles(const CObjectVector<PluginPanelItem> &pluginPanelItems) UString archiveNameSrc = resultPath; UString arcName = archiveNameSrc; - const CArcInfoEx &arcInfo = codecs->Formats[archiverIndex]; int prevFormat = archiverIndex; - - SetArcName(arcName, arcInfo); + SetArcName(arcName, codecs->Formats[archiverIndex]); const CActionSet *actionSet = &k_ActionSet_Add; @@ -454,13 +452,14 @@ HRESULT CompressFiles(const CObjectVector<PluginPanelItem> &pluginPanelItems) const int kMethodRadioIndex = kArchiveNameIndex + 2; const int kModeRadioIndex = kMethodRadioIndex + 7; - const CArcInfoEx &arcInfo = codecs->Formats[archiverIndex]; char updateAddToArchiveString[512]; - const AString s = UnicodeStringToMultiByte(arcInfo.Name, CP_OEMCP); - - sprintf(updateAddToArchiveString, + { + const CArcInfoEx &arcInfo = codecs->Formats[archiverIndex]; + const AString s = UnicodeStringToMultiByte(arcInfo.Name, CP_OEMCP); + sprintf(updateAddToArchiveString, g_StartupInfo.GetMsgString(NMessageID::kUpdateAddToArchive), (const char *)s); + } int methodIndex = 0; int i; @@ -471,7 +470,7 @@ HRESULT CompressFiles(const CObjectVector<PluginPanelItem> &pluginPanelItems) break; } - struct CInitDialogItem initItems[]= + const struct CInitDialogItem initItems[]= { { DI_DOUBLEBOX, 3, 1, 72, kYSize - 2, false, false, 0, false, NMessageID::kUpdateTitle, NULL, NULL }, @@ -532,12 +531,12 @@ HRESULT CompressFiles(const CObjectVector<PluginPanelItem> &pluginPanelItems) { CIntVector indices; CSysStringVector archiverNames; - FOR_VECTOR (i, codecs->Formats) + FOR_VECTOR (k, codecs->Formats) { - const CArcInfoEx &arc = codecs->Formats[i]; + const CArcInfoEx &arc = codecs->Formats[k]; if (arc.UpdateEnabled) { - indices.Add(i); + indices.Add(k); archiverNames.Add(GetSystemString(arc.Name, CP_OEMCP)); } } diff --git a/CPP/7zip/UI/FileManager/FM.cpp b/CPP/7zip/UI/FileManager/FM.cpp index 35b757dd..ce39011e 100644 --- a/CPP/7zip/UI/FileManager/FM.cpp +++ b/CPP/7zip/UI/FileManager/FM.cpp @@ -844,17 +844,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (needOpenFile && !archiveIsOpened || res != S_OK) { - UString message = L"Error"; + UString m = L"Error"; if (res == S_FALSE || res == S_OK) { - message = MyFormatNew(encrypted ? + m = MyFormatNew(encrypted ? IDS_CANT_OPEN_ENCRYPTED_ARCHIVE : IDS_CANT_OPEN_ARCHIVE, fullPath); } else if (res != S_OK) - message = HResultToMessage(res); - ErrorMessage(message); + m = HResultToMessage(res); + ErrorMessage(m); return -1; } diff --git a/CPP/7zip/UI/FileManager/PanelFolderChange.cpp b/CPP/7zip/UI/FileManager/PanelFolderChange.cpp index 91b6feb1..aaf3f867 100644 --- a/CPP/7zip/UI/FileManager/PanelFolderChange.cpp +++ b/CPP/7zip/UI/FileManager/PanelFolderChange.cpp @@ -504,10 +504,10 @@ bool CPanel::OnComboBoxCommand(UINT code, LPARAM /* param */, LRESULT &result) { FString s = driveStrings[i]; ComboBoxPaths.Add(fs2us(s)); - int iconIndex = GetRealIconIndex(s, 0); + int iconIndex2 = GetRealIconIndex(s, 0); if (s.Len() > 0 && s.Back() == FCHAR_PATH_SEPARATOR) s.DeleteBack(); - AddComboBoxItem(fs2us(s), iconIndex, 1, false); + AddComboBoxItem(fs2us(s), iconIndex2, 1, false); } name = RootFolder_GetName_Network(iconIndex); diff --git a/CPP/7zip/UI/FileManager/PanelMenu.cpp b/CPP/7zip/UI/FileManager/PanelMenu.cpp index 8a9f6276..c5b07825 100644 --- a/CPP/7zip/UI/FileManager/PanelMenu.cpp +++ b/CPP/7zip/UI/FileManager/PanelMenu.cpp @@ -189,9 +189,9 @@ void CPanel::Properties() } else { - for (UInt32 i = 0; i < dataSize; i++) + for (UInt32 k = 0; k < dataSize; k++) { - Byte b = ((const Byte *)data)[i]; + Byte b = ((const Byte *)data)[k]; s += GetHex((Byte)((b >> 4) & 0xF)); s += GetHex((Byte)(b & 0xF)); } @@ -245,8 +245,6 @@ void CPanel::Properties() } } - CMyComPtr<IGetFolderArcProps> getFolderArcProps; - _folder.QueryInterface(IID_IGetFolderArcProps, &getFolderArcProps); if (getFolderArcProps) { CMyComPtr<IFolderArcProps> getProps; diff --git a/CPP/7zip/UI/FileManager/ProgressDialog2.cpp b/CPP/7zip/UI/FileManager/ProgressDialog2.cpp index 378ad903..8c38b81a 100644 --- a/CPP/7zip/UI/FileManager/ProgressDialog2.cpp +++ b/CPP/7zip/UI/FileManager/ProgressDialog2.cpp @@ -939,8 +939,8 @@ INT_PTR CProgressDialog::Create(const UString &title, NWindows::CThread &thread, CWaitCursor waitCursor; HANDLE h[] = { thread, _createDialogEvent }; - WRes res = WaitForMultipleObjects(ARRAY_SIZE(h), h, FALSE, kCreateDelay); - if (res == WAIT_OBJECT_0 && !Sync.ThereIsMessage()) + WRes res2 = WaitForMultipleObjects(ARRAY_SIZE(h), h, FALSE, kCreateDelay); + if (res2 == WAIT_OBJECT_0 && !Sync.ThereIsMessage()) return 0; } _title = title; diff --git a/CPP/7zip/UI/GUI/BenchmarkDialog.cpp b/CPP/7zip/UI/GUI/BenchmarkDialog.cpp index b7c95950..c7d13bc2 100644 --- a/CPP/7zip/UI/GUI/BenchmarkDialog.cpp +++ b/CPP/7zip/UI/GUI/BenchmarkDialog.cpp @@ -242,13 +242,17 @@ bool CBenchmarkDialog::OnSize(WPARAM /* wParam */, int xSize, int ySize) int bx1, bx2, by; GetItemSizes(IDCANCEL, bx1, by); GetItemSizes(IDHELP, bx2, by); - int y = ySize - my - by; - int x = xSize - mx - bx1; - InvalidateRect(NULL); + { + int y = ySize - my - by; + int x = xSize - mx - bx1; + + InvalidateRect(NULL); + + MoveItem(IDCANCEL, x, y, bx1, by); + MoveItem(IDHELP, x - mx - bx2, y, bx2, by); + } - MoveItem(IDCANCEL, x, y, bx1, by); - MoveItem(IDHELP, x - mx - bx2, y, bx2, by); if (_consoleEdit) { int yPos = ySize - my - by; diff --git a/CPP/7zip/UI/GUI/CompressDialog.cpp b/CPP/7zip/UI/GUI/CompressDialog.cpp index 45d3c59a..14a9d31c 100644 --- a/CPP/7zip/UI/GUI/CompressDialog.cpp +++ b/CPP/7zip/UI/GUI/CompressDialog.cpp @@ -713,16 +713,18 @@ void CCompressDialog::OnOK() } SaveOptionsInMem(); - UString s; - if (!GetFinalPath_Smart(s)) { - ShowErrorMessage(*this, k_IncorrectPathMessage); - return; + UString s; + if (!GetFinalPath_Smart(s)) + { + ShowErrorMessage(*this, k_IncorrectPathMessage); + return; + } + + m_RegistryInfo.ArcPaths.Clear(); + AddUniqueString(m_RegistryInfo.ArcPaths, s); + Info.ArcPath = s; } - - m_RegistryInfo.ArcPaths.Clear(); - AddUniqueString(m_RegistryInfo.ArcPaths, s); - Info.ArcPath = s; Info.UpdateMode = (NCompressDialog::NUpdateMode::EEnum)k_UpdateMode_Vals[m_UpdateMode.GetCurSel()];; Info.PathMode = (NWildcard::ECensorPathMode)k_PathMode_Vals[m_PathMode.GetCurSel()]; @@ -1007,15 +1009,17 @@ void CCompressDialog::SetLevel() m_Level.ResetContent(); const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; const CArcInfoEx &ai = (*ArcFormats)[GetFormatIndex()]; - int index = FindRegistryFormat(ai.Name); UInt32 level = 5; - if (index >= 0) { - const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; - if (fo.Level <= 9) - level = fo.Level; - else - level = 9; + int index = FindRegistryFormat(ai.Name); + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; + if (fo.Level <= 9) + level = fo.Level; + else + level = 9; + } } for (unsigned i = 0; i <= 9; i++) @@ -1469,18 +1473,23 @@ void CCompressDialog::SetSolidBlockSize() UInt32 defaultBlockSize = (UInt32)(Int32)-1; const CArcInfoEx &ai = (*ArcFormats)[GetFormatIndex()]; - int index = FindRegistryFormat(ai.Name); - if (index >= 0) { - const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; - if (fo.Method.IsEqualTo_NoCase(GetMethodSpec())) - defaultBlockSize = fo.BlockLogSize; + int index = FindRegistryFormat(ai.Name); + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; + if (fo.Method.IsEqualTo_NoCase(GetMethodSpec())) + defaultBlockSize = fo.BlockLogSize; + } } - index = (int)m_Solid.AddString(LangString(IDS_COMPRESS_NON_SOLID)); - m_Solid.SetItemData(index, (UInt32)kNoSolidBlockSize); - m_Solid.SetCurSel(0); - bool needSet = defaultBlockSize == (UInt32)(Int32)-1; + { + int index = (int)m_Solid.AddString(LangString(IDS_COMPRESS_NON_SOLID)); + m_Solid.SetItemData(index, (UInt32)kNoSolidBlockSize); + m_Solid.SetCurSel(0); + } + + bool needSet = (defaultBlockSize == (UInt32)(Int32)-1); for (unsigned i = 20; i <= 36; i++) { @@ -1495,8 +1504,11 @@ void CCompressDialog::SetSolidBlockSize() m_Solid.SetItemData(index, (UInt32)i); } - index = (int)m_Solid.AddString(LangString(IDS_COMPRESS_SOLID)); - m_Solid.SetItemData(index, kSolidBlockSize); + { + int index = (int)m_Solid.AddString(LangString(IDS_COMPRESS_SOLID)); + m_Solid.SetItemData(index, kSolidBlockSize); + } + if (defaultBlockSize == (UInt32)(Int32)-1) defaultBlockSize = kSolidBlockSize; if (defaultBlockSize != kNoSolidBlockSize) @@ -1514,13 +1526,15 @@ void CCompressDialog::SetNumThreads() UInt32 numHardwareThreads = NSystem::GetNumberOfProcessors(); UInt32 defaultValue = numHardwareThreads; - const CArcInfoEx &ai = (*ArcFormats)[GetFormatIndex()]; - int index = FindRegistryFormat(ai.Name); - if (index >= 0) { - const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; - if (fo.Method.IsEqualTo_NoCase(GetMethodSpec()) && fo.NumThreads != (UInt32)(Int32)-1) - defaultValue = fo.NumThreads; + const CArcInfoEx &ai = (*ArcFormats)[GetFormatIndex()]; + int index = FindRegistryFormat(ai.Name); + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.Formats[index]; + if (fo.Method.IsEqualTo_NoCase(GetMethodSpec()) && fo.NumThreads != (UInt32)(Int32)-1) + defaultValue = fo.NumThreads; + } } UInt32 numAlgoThreadsMax = 1; diff --git a/CPP/Common/TextConfig.cpp b/CPP/Common/TextConfig.cpp index 7606ee7b..9ae4074b 100644 --- a/CPP/Common/TextConfig.cpp +++ b/CPP/Common/TextConfig.cpp @@ -87,7 +87,7 @@ bool GetTextConfig(const AString &s, CObjectVector<CTextConfigPair> &pairs) break; if (c == '\\') { - char c = s[pos++]; + c = s[pos++]; switch (c) { case 'n': message += '\n'; break; diff --git a/CPP/Windows/Control/ComboBox.cpp b/CPP/Windows/Control/ComboBox.cpp index c6d5a8d6..febc61ef 100644 --- a/CPP/Windows/Control/ComboBox.cpp +++ b/CPP/Windows/Control/ComboBox.cpp @@ -51,7 +51,7 @@ LRESULT CComboBox::GetLBText(int index, UString &s) return len; if (len > len2) len = len2; - s.ReleaseBuf_CalcLen(len); + s.ReleaseBuf_CalcLen((unsigned)len); return len; } AString sa; diff --git a/DOC/7zip.inf b/DOC/7zip.inf index 80e6355d..cea43772 100644 --- a/DOC/7zip.inf +++ b/DOC/7zip.inf @@ -10,8 +10,8 @@ AppName = "7-Zip" InstallDir = %CE1%\%AppName% [Strings] -AppVer = "16.00" -AppDate = "2016-05-10" +AppVer = "16.01" +AppDate = "2016-05-19" [CEDevice] ; ProcessorType = 2577 ; ARM diff --git a/DOC/7zip.nsi b/DOC/7zip.nsi index 49ee7956..66c47202 100644 --- a/DOC/7zip.nsi +++ b/DOC/7zip.nsi @@ -2,7 +2,7 @@ ;Defines !define VERSION_MAJOR 16 -!define VERSION_MINOR 00 +!define VERSION_MINOR 01 !define VERSION_POSTFIX_FULL "" !ifdef WIN64 !ifdef IA64 diff --git a/DOC/7zip.wxs b/DOC/7zip.wxs index 30deffa7..81c3768b 100644 --- a/DOC/7zip.wxs +++ b/DOC/7zip.wxs @@ -1,7 +1,7 @@ <?xml version="1.0"?> <?define VerMajor = "16" ?> -<?define VerMinor = "00" ?> +<?define VerMinor = "01" ?> <?define VerBuild = "00" ?> <?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?> <?define MmHex = "$(var.VerMajor)$(var.VerMinor)" ?> @@ -59,6 +59,7 @@ <?define CompFormats = "$(var.CompId)10" ?> <?define CompCodecs = "$(var.CompId)11" ?> <?define CompLang = "$(var.CompId)12" ?> +<?define CompShellExt2 = "$(var.CompId)13" ?> <?define CompInstallRegCU = "$(var.CompId)80" ?> <?define CompInstallRegLM = "$(var.CompId)81" ?> <?define CompInstallRegWild = "$(var.CompId)82" ?> @@ -190,7 +191,7 @@ <?if $(var.MyCPU) = "x64" ?> - <Component Id="ShellExt32" Guid="$(var.CompShellExt)" DiskId="1" Win64="no"> + <Component Id="ShellExt32" Guid="$(var.CompShellExt2)" DiskId="1" Win64="no"> <File Id="_7zip32.dll" Name="7-zip32.dll" /> <Registry Id="shellReg0_32" Action="write" Type="string" Root="HKCR" Key="CLSID\$(var.ShellExtId)\InprocServer32" diff --git a/DOC/readme.txt b/DOC/readme.txt index 907cd5be..1f09cbc5 100644 --- a/DOC/readme.txt +++ b/DOC/readme.txt @@ -1,4 +1,4 @@ -7-Zip 16.00 Sources +7-Zip 16.01 Sources ------------------- 7-Zip is a file archiver for Windows. diff --git a/DOC/src-history.txt b/DOC/src-history.txt index bf6e2d0c..60e31bcd 100644 --- a/DOC/src-history.txt +++ b/DOC/src-history.txt @@ -1,6 +1,12 @@ HISTORY of the 7-Zip source code -------------------------------- +16.01 2016-05-19 +------------------------- +- Some bugs were fixed, +- Some internal changes to reduce the number of compiler warnings. + + 16.00 2016-05-10 ------------------------- - 7-Zip now can extract multivolume ZIP archives (z01, z02, ... , zip). |