From dd3e521d445dc23e502d38fdf94a4202cc8ab884 Mon Sep 17 00:00:00 2001 From: Ryan Knuth Date: Mon, 28 Apr 2025 11:47:28 -0700 Subject: [PATCH 1/3] Bring changes from office over This brings over changes Office needs to build so we can more easily migrate changes in the future. 1. Comment out a bunch of unreferenced parameters. 2. Explicitly cast in comparisons 3. A few optimizations 4. Some SAL annotations 5. Remove typedef from enums. Specify default storage type for enums. 6. Remove problmatic unused ZipObject and ZipObjectWriter ctors 7. Remove u8 from char* definitions. This is incompatible with C++20 which would need to us char8_t* 8. Use localtime_s over localtime. This ctor doesn't set m_localTime so I'm not sure if this even matters. 9. Use LONG instead of long. These have different types on cross platforms --- src/inc/internal/AppxBlockMapObject.hpp | 2 +- src/inc/internal/AppxBundleManifest.hpp | 4 +- src/inc/internal/AppxFile.hpp | 4 +- src/inc/internal/AppxManifestObject.hpp | 12 +-- src/inc/internal/BlockMapStream.hpp | 6 +- src/inc/internal/FileStream.hpp | 2 +- src/inc/internal/HashStream.hpp | 4 +- src/inc/internal/InflateStream.hpp | 2 +- src/inc/internal/MappingFileParser.hpp | 4 +- src/inc/internal/ObjectBase.hpp | 6 +- src/inc/internal/RangeStream.hpp | 2 +- src/inc/internal/VectorStream.hpp | 2 +- src/inc/internal/ZipObject.hpp | 1 - src/inc/internal/ZipObjectWriter.hpp | 2 - src/inc/public/MSIXWindows.hpp | 2 + src/inc/public/MsixErrors.hpp | 2 + src/inc/shared/StreamBase.hpp | 2 +- .../PAL/Applicability/Win32/Applicability.cpp | 4 +- src/msix/PAL/Crypto/Win32/Crypto.cpp | 1 + .../PAL/FileSystem/Win32/DirectoryObject.cpp | 4 +- .../Signature/Win32/SignatureValidator.cpp | 3 +- src/msix/PAL/XML/msxml6/XmlObject.cpp | 38 ++++---- src/msix/common/AppxFactory.cpp | 6 +- src/msix/common/AppxManifestObject.cpp | 88 +++++++++---------- src/msix/common/AppxManifestValidation.cpp | 2 +- src/msix/common/Encoding.cpp | 8 +- src/msix/common/Exceptions.cpp | 2 +- src/msix/common/TimeHelpers.cpp | 7 +- src/msix/common/ZipObject.cpp | 11 --- src/msix/msix.cpp | 3 + src/msix/pack/AppxPackageWriter.cpp | 4 +- src/msix/pack/ZipObjectWriter.cpp | 18 +--- src/msix/unpack/ApplicabilityCommon.cpp | 6 +- src/msix/unpack/AppxBlockMapObject.cpp | 6 +- src/msix/unpack/AppxPackageObject.cpp | 2 +- src/msix/unpack/InflateStream.cpp | 6 +- 36 files changed, 133 insertions(+), 145 deletions(-) diff --git a/src/inc/internal/AppxBlockMapObject.hpp b/src/inc/internal/AppxBlockMapObject.hpp index 9813ca288..67db40c23 100644 --- a/src/inc/internal/AppxBlockMapObject.hpp +++ b/src/inc/internal/AppxBlockMapObject.hpp @@ -123,7 +123,7 @@ namespace MSIX { return static_cast(Error::OK); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE ValidateFileHash(IStream *fileStream, BOOL *isValid) noexcept override + HRESULT STDMETHODCALLTYPE ValidateFileHash(IStream */*fileStream*/, BOOL */*isValid*/) noexcept override { return static_cast(Error::NotImplemented); } diff --git a/src/inc/internal/AppxBundleManifest.hpp b/src/inc/internal/AppxBundleManifest.hpp index ed0b1251a..2e6e91956 100644 --- a/src/inc/internal/AppxBundleManifest.hpp +++ b/src/inc/internal/AppxBundleManifest.hpp @@ -53,7 +53,7 @@ namespace MSIX { // IVerifierObject bool HasStream() override { return !!m_stream; } ComPtr GetStream() override { return m_stream; } - ComPtr GetValidationStream(const std::string& part, const ComPtr&) override { NOTSUPPORTED; } + ComPtr GetValidationStream(const std::string& /*part*/, const ComPtr&) override { NOTSUPPORTED; } const std::string& GetPublisher() override { NOTSUPPORTED; } // IAppxBundleManifestReader @@ -91,7 +91,7 @@ namespace MSIX { return S_OK; } - HRESULT STDMETHODCALLTYPE GetDXFeatureLevel(DX_FEATURE_LEVEL *dxFeatureLevel) noexcept override + HRESULT STDMETHODCALLTYPE GetDXFeatureLevel(DX_FEATURE_LEVEL */*dxFeatureLevel*/) noexcept override { return static_cast(Error::NotImplemented); } diff --git a/src/inc/internal/AppxFile.hpp b/src/inc/internal/AppxFile.hpp index 9f96a7a2a..a9a7f094a 100644 --- a/src/inc/internal/AppxFile.hpp +++ b/src/inc/internal/AppxFile.hpp @@ -43,7 +43,7 @@ namespace MSIX { return static_cast(Error::OK); } - virtual HRESULT STDMETHODCALLTYPE GetContentType(LPWSTR* contentType) noexcept override + virtual HRESULT STDMETHODCALLTYPE GetContentType(LPWSTR* /*contentType*/) noexcept override { return static_cast(Error::NotImplemented); } @@ -72,7 +72,7 @@ namespace MSIX { } CATCH_RETURN(); // IAppxFileUtf8 - virtual HRESULT STDMETHODCALLTYPE GetContentType(LPSTR* contentType) noexcept override + virtual HRESULT STDMETHODCALLTYPE GetContentType(LPSTR* /*contentType*/) noexcept override { return static_cast(Error::NotImplemented); } diff --git a/src/inc/internal/AppxManifestObject.hpp b/src/inc/internal/AppxManifestObject.hpp index b02061d4f..7b2d08596 100644 --- a/src/inc/internal/AppxManifestObject.hpp +++ b/src/inc/internal/AppxManifestObject.hpp @@ -135,7 +135,7 @@ namespace MSIX { {} // IAppxManifestApplication - HRESULT STDMETHODCALLTYPE GetStringValue(LPCWSTR name, LPWSTR* value) noexcept override + HRESULT STDMETHODCALLTYPE GetStringValue(LPCWSTR /*name*/, LPWSTR* /*value*/) noexcept override { return static_cast(Error::NotImplemented); } @@ -146,7 +146,7 @@ namespace MSIX { } CATCH_RETURN(); // IAppxManifestApplicationUtf8 - HRESULT STDMETHODCALLTYPE GetStringValue(LPCSTR name, LPSTR* value) noexcept override + HRESULT STDMETHODCALLTYPE GetStringValue(LPCSTR /*name*/, LPSTR* /*value*/) noexcept override { return static_cast(Error::NotImplemented); } @@ -368,7 +368,7 @@ namespace MSIX { class AppxManifestQualifiedResource final : public ComClass { public: - AppxManifestQualifiedResource(IMsixFactory* factory, std::string& language, std::string& scale, std::string& DXFeatureLevel) : + AppxManifestQualifiedResource(IMsixFactory* factory, std::string& language, std::string& /*scale*/, std::string& /*DXFeatureLevel*/) : m_factory(factory), m_language(language) { //TODO: Process and assign scale and DXFeatureLevel @@ -381,12 +381,12 @@ namespace MSIX { return m_factory->MarshalOutString(m_language, language); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE GetScale(UINT32 *scale) noexcept override try + HRESULT STDMETHODCALLTYPE GetScale(UINT32 */*scale*/) noexcept override try { return static_cast(Error::NotImplemented); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE GetDXFeatureLevel(DX_FEATURE_LEVEL *dxFeatureLevel) noexcept override try + HRESULT STDMETHODCALLTYPE GetDXFeatureLevel(DX_FEATURE_LEVEL */*dxFeatureLevel*/) noexcept override try { return static_cast(Error::NotImplemented); } CATCH_RETURN(); @@ -446,7 +446,7 @@ namespace MSIX { // IVerifierObject bool HasStream() override { return !!m_stream; } ComPtr GetStream() override { return m_stream; } - ComPtr GetValidationStream(const std::string& part, const ComPtr&) override { NOTSUPPORTED; } + ComPtr GetValidationStream(const std::string& /*part*/, const ComPtr&) override { NOTSUPPORTED; } const std::string& GetPublisher() override { NOTSUPPORTED; } // IAppxManifestObject diff --git a/src/inc/internal/BlockMapStream.hpp b/src/inc/internal/BlockMapStream.hpp index 039d7957b..efb18198d 100644 --- a/src/inc/internal/BlockMapStream.hpp +++ b/src/inc/internal/BlockMapStream.hpp @@ -59,7 +59,7 @@ namespace MSIX { // Build a vector of all HashStream->RangeStream's for the blocks in the blockmap std::uint64_t offset = 0; std::uint64_t sizeRemaining = m_streamSize; - for (auto block = blocks.begin(); ((sizeRemaining != 0) && (block != blocks.end())); block++) + for (auto block = blocks.begin(); ((sizeRemaining != 0) && (block != blocks.end())); ++block) { auto rangeStream = ComPtr::Make(offset, std::min(sizeRemaining, BLOCKMAP_BLOCK_SIZE), stream.Get()); auto hashStream = ComPtr::Make(rangeStream, block->hash); @@ -104,7 +104,7 @@ namespace MSIX { return S_OK; } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE Read(void* buffer, ULONG countBytes, ULONG* actualRead) noexcept override try + HRESULT STDMETHODCALLTYPE Read(_Out_cap_(countBytes) void* buffer, ULONG countBytes, ULONG* actualRead) noexcept override try { std::uint32_t bytesRead = 0; if (m_relativePosition < m_streamSize) @@ -114,7 +114,7 @@ namespace MSIX { { if ((m_currentBlock->offset + m_currentBlock->size) <= m_relativePosition) { - m_currentBlock++; + ++m_currentBlock; } else if (m_currentBlock->offset <= m_relativePosition) { diff --git a/src/inc/internal/FileStream.hpp b/src/inc/internal/FileStream.hpp index 66a4d5338..bbec2c5de 100644 --- a/src/inc/internal/FileStream.hpp +++ b/src/inc/internal/FileStream.hpp @@ -85,7 +85,7 @@ namespace MSIX { return static_cast(Error::OK); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE Read(void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override try + HRESULT STDMETHODCALLTYPE Read(_Out_cap_(countBytes) void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override try { if (bytesRead) { *bytesRead = 0; } ULONG result = static_cast(std::fread(buffer, sizeof(std::uint8_t), countBytes, m_file)); diff --git a/src/inc/internal/HashStream.hpp b/src/inc/internal/HashStream.hpp index 6ada6b93b..d6faba7e3 100644 --- a/src/inc/internal/HashStream.hpp +++ b/src/inc/internal/HashStream.hpp @@ -98,7 +98,7 @@ namespace MSIX { return static_cast(Error::OK); } CATCH_RETURN(); - void CacheRead(void* buffer, ULONG countBytes, ULONG* actualRead) + void CacheRead(_Out_cap_(countBytes) void* buffer, ULONG countBytes, ULONG* actualRead) { ThrowErrorIf(Error::Stg_E_Invalidpointer, (buffer == nullptr), "bad input"); ULONG bytesToRead = std::min((std::uint32_t)countBytes, static_cast((std::uint64_t)m_cacheBuffer->size() - m_relativePosition)); @@ -112,7 +112,7 @@ namespace MSIX { if (actualRead) { *actualRead = bytesToRead; } } - HRESULT STDMETHODCALLTYPE Read(void* buffer, ULONG countBytes, ULONG* actualRead) noexcept override try + HRESULT STDMETHODCALLTYPE Read(_Out_cap_(countBytes) void* buffer, ULONG countBytes, ULONG* actualRead) noexcept override try { Validate(); if (m_cacheBuffer.get() == nullptr) diff --git a/src/inc/internal/InflateStream.hpp b/src/inc/internal/InflateStream.hpp index 5ac936417..2ffb9671e 100644 --- a/src/inc/internal/InflateStream.hpp +++ b/src/inc/internal/InflateStream.hpp @@ -26,7 +26,7 @@ namespace MSIX { HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER move, DWORD origin, ULARGE_INTEGER *newPosition) noexcept override; HRESULT STDMETHODCALLTYPE Read(void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override; - HRESULT STDMETHODCALLTYPE Write(void const *buffer, ULONG countBytes, ULONG *bytesWritten) noexcept override + HRESULT STDMETHODCALLTYPE Write(void const */*buffer*/, ULONG /*countBytes*/, ULONG */*bytesWritten*/) noexcept override { return static_cast(Error::NotImplemented); } diff --git a/src/inc/internal/MappingFileParser.hpp b/src/inc/internal/MappingFileParser.hpp index 954dd6b42..e691afef2 100644 --- a/src/inc/internal/MappingFileParser.hpp +++ b/src/inc/internal/MappingFileParser.hpp @@ -9,13 +9,13 @@ namespace MSIX { - typedef enum : UINT32 + enum HandlerState : UINT32 { Continue = 0, Stop, SkipSection, Fail - } HandlerState; + }; enum SectionID { diff --git a/src/inc/internal/ObjectBase.hpp b/src/inc/internal/ObjectBase.hpp index e18b4c77e..aa89c6843 100644 --- a/src/inc/internal/ObjectBase.hpp +++ b/src/inc/internal/ObjectBase.hpp @@ -176,7 +176,7 @@ class TypeList std::tuple fields; template - inline typename std::enable_if::type for_each(FuncT, Args&&... args) { } + inline typename std::enable_if::type for_each(FuncT, Args&&... /*args*/) { } template inline typename std::enable_if::type for_each(FuncT f, Args&&... args) @@ -202,7 +202,7 @@ class StructuredObject : public TypeList size_t Size() { size_t result = 0; - this->for_each([](auto& field, std::size_t index, size_t& result) + this->for_each([](auto& field, std::size_t /*index*/, size_t& result) { result += field.Size(); }, result); @@ -213,7 +213,7 @@ class StructuredObject : public TypeList { THROW_IF_PACK_NOT_ENABLED std::vector bytes; - this->for_each([](auto& field, std::size_t index, std::vector& bytes) + this->for_each([](auto& field, std::size_t /*index*/, std::vector& bytes) { field.GetBytes(bytes); }, bytes); diff --git a/src/inc/internal/RangeStream.hpp b/src/inc/internal/RangeStream.hpp index 8fd5ad4b1..3d4e43710 100644 --- a/src/inc/internal/RangeStream.hpp +++ b/src/inc/internal/RangeStream.hpp @@ -73,7 +73,7 @@ namespace MSIX { return static_cast(Error::OK); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE Read(void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override try + HRESULT STDMETHODCALLTYPE Read(_Out_cap_(countBytes) void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override try { LARGE_INTEGER offset = {0}; offset.QuadPart = m_relativePosition + m_offset; diff --git a/src/inc/internal/VectorStream.hpp b/src/inc/internal/VectorStream.hpp index 881ff0e03..3aa9c7451 100644 --- a/src/inc/internal/VectorStream.hpp +++ b/src/inc/internal/VectorStream.hpp @@ -18,7 +18,7 @@ namespace MSIX { public: VectorStream(std::vector* data) : m_data(data) {} - HRESULT STDMETHODCALLTYPE Read(void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override try + HRESULT STDMETHODCALLTYPE Read(_Out_cap_(countBytes) void* buffer, ULONG countBytes, ULONG* bytesRead) noexcept override try { ULONG amountToRead = std::min(countBytes, static_cast(m_data->size() - m_offset)); if (amountToRead > 0) { memcpy(buffer, &(m_data->at(m_offset)), amountToRead); } diff --git a/src/inc/internal/ZipObject.hpp b/src/inc/internal/ZipObject.hpp index 8363b9436..1a31c11c0 100644 --- a/src/inc/internal/ZipObject.hpp +++ b/src/inc/internal/ZipObject.hpp @@ -455,7 +455,6 @@ namespace MSIX { { public: ZipObject(const ComPtr& stream) : m_stream(stream) {} - ZipObject(const ComPtr& storageObject); protected: EndCentralDirectoryRecord m_endCentralDirectoryRecord; diff --git a/src/inc/internal/ZipObjectWriter.hpp b/src/inc/internal/ZipObjectWriter.hpp index 33b35417b..59db6ab62 100644 --- a/src/inc/internal/ZipObjectWriter.hpp +++ b/src/inc/internal/ZipObjectWriter.hpp @@ -46,8 +46,6 @@ namespace MSIX { public: ZipObjectWriter(const ComPtr& stream); - ZipObjectWriter(const ComPtr& storageObject); - // IStorage methods std::vector GetFileNames(FileNameOptions options) override; ComPtr GetFile(const std::string& fileName) override; diff --git a/src/inc/public/MSIXWindows.hpp b/src/inc/public/MSIXWindows.hpp index 1d3374334..fe890ef0b 100644 --- a/src/inc/public/MSIXWindows.hpp +++ b/src/inc/public/MSIXWindows.hpp @@ -21,7 +21,9 @@ #endif #define UNICODE +#ifndef NOMINMAX #define NOMINMAX +#endif #include // Windows.h defines max and min, which does NOT play nice at all with std::min / std::max usage from #undef max diff --git a/src/inc/public/MsixErrors.hpp b/src/inc/public/MsixErrors.hpp index 19502eb58..bf9ac9b8e 100644 --- a/src/inc/public/MsixErrors.hpp +++ b/src/inc/public/MsixErrors.hpp @@ -6,6 +6,8 @@ #ifndef MSIX_MSIX_ERRORS__H #define MSIX_MSIX_ERRORS__H +#include + namespace MSIX { static const std::uint32_t ERROR_FACILITY = 0x8BAD0000; // Facility 2989 diff --git a/src/inc/shared/StreamBase.hpp b/src/inc/shared/StreamBase.hpp index 41ea6b097..9ad10cc7c 100644 --- a/src/inc/shared/StreamBase.hpp +++ b/src/inc/shared/StreamBase.hpp @@ -135,7 +135,7 @@ namespace MSIX { virtual std::string GetName() override { NOTIMPLEMENTED; } template - static ULONG Read(const ComPtr& stream, T* value) + static ULONG Read(const ComPtr& stream, _Out_cap_(sizeof(T)) T* value) { ULONG result = 0; ThrowHrIfFailed(stream->Read(value, static_cast(sizeof(T)), &result)); diff --git a/src/msix/PAL/Applicability/Win32/Applicability.cpp b/src/msix/PAL/Applicability/Win32/Applicability.cpp index b847711cc..cfea724b9 100644 --- a/src/msix/PAL/Applicability/Win32/Applicability.cpp +++ b/src/msix/PAL/Applicability/Win32/Applicability.cpp @@ -4,8 +4,8 @@ // #include #include -#include -#include +#include +#include #include #include "Applicability.hpp" diff --git a/src/msix/PAL/Crypto/Win32/Crypto.cpp b/src/msix/PAL/Crypto/Win32/Crypto.cpp index 9f1b7ca55..51bf98da6 100644 --- a/src/msix/PAL/Crypto/Win32/Crypto.cpp +++ b/src/msix/PAL/Crypto/Win32/Crypto.cpp @@ -14,6 +14,7 @@ #include #include +#include struct unique_hash_handle_deleter { void operator()(BCRYPT_HASH_HANDLE h) const { diff --git a/src/msix/PAL/FileSystem/Win32/DirectoryObject.cpp b/src/msix/PAL/FileSystem/Win32/DirectoryObject.cpp index 5cfcdb8e1..9e2521fc9 100644 --- a/src/msix/PAL/FileSystem/Win32/DirectoryObject.cpp +++ b/src/msix/PAL/FileSystem/Win32/DirectoryObject.cpp @@ -41,7 +41,7 @@ namespace MSIX } template - void WalkDirectory(const std::string& root, WalkOptions options, Lambda& visitor) + void WalkDirectory(const std::string& root, WalkOptions options, Lambda visitor) { static std::string dot("."); static std::string dotdot(".."); @@ -323,7 +323,7 @@ namespace MSIX auto rootSize = m_root.size() + 1; // plus separator WalkDirectory(m_root, WalkOptions::Recursive | WalkOptions::Files, [&]( std::string root, - WalkOptions option, + WalkOptions /*option*/, std::string&& name, std::uint64_t lastWrite) { diff --git a/src/msix/PAL/Signature/Win32/SignatureValidator.cpp b/src/msix/PAL/Signature/Win32/SignatureValidator.cpp index d433b93a6..16eed06a8 100644 --- a/src/msix/PAL/Signature/Win32/SignatureValidator.cpp +++ b/src/msix/PAL/Signature/Win32/SignatureValidator.cpp @@ -346,7 +346,7 @@ namespace MSIX &cbDecoded)) { unique_local_alloc_handle basicConstraints(basicConstraintsT); - return basicConstraintsT->fCA ? true : false; + return basicConstraintsT->fCA; } return false; } @@ -495,6 +495,7 @@ namespace MSIX bool SignatureValidator::Validate( IMsixFactory* factory, + IMsixFactory* /*factory*/, MSIX_VALIDATION_OPTION option, const ComPtr& stream, AppxSignatureObject* signatureObject, diff --git a/src/msix/PAL/XML/msxml6/XmlObject.cpp b/src/msix/PAL/XML/msxml6/XmlObject.cpp index 01a48305b..a4d0bda73 100644 --- a/src/msix/PAL/XML/msxml6/XmlObject.cpp +++ b/src/msix/PAL/XML/msxml6/XmlObject.cpp @@ -121,7 +121,7 @@ class Variant VARIANT* AddressOf() { - VariantClear(&m_variant); + (void)VariantClear(&m_variant); return &m_variant; } @@ -220,10 +220,10 @@ class MSXMLElement final : public ComClassselectNodes(xPath, &list)); - long count = 0; + LONG count = 0; ThrowHrIfFailed(list->get_length(&count)); std::vector> elementsEnum; - for(long index=0; index < count; index++) + for(LONG index=0; index < count; index++) { ComPtr node; ThrowHrIfFailed(list->get_item(index, &node)); @@ -286,10 +286,10 @@ class MSXMLElement final : public ComClassselectNodes(xPath, &list)); - long count = 0; + LONG count = 0; ThrowHrIfFailed(list->get_length(&count)); std::vector> elementsEnum; - for(long index=0; index < count; index++) + for(LONG index=0; index < count; index++) { ComPtr node; ThrowHrIfFailed(list->get_item(index, &node)); @@ -351,7 +351,7 @@ class MSXMLDom final : public ComClass ComPtr resource(m_factory->GetResource(item.schema)); auto schema = ComPtr::Make(resource, emptyManager)->GetDomDocument(); - long readyState = 0; + LONG readyState = 0; ThrowHrIfFailed(schema->get_readyState(&readyState)); ThrowErrorIfNot(Error::Unexpected, (4 == readyState), "The document has not been completely loaded."); @@ -412,12 +412,12 @@ class MSXMLDom final : public ComClass ComPtr namespaceAliasesToStrip; Bstr ignorableNamespaces(L"@IgnorableNamespaces"); ThrowHrIfFailed(element->selectNodes(ignorableNamespaces, &namespaceAliasesToStrip)); - long count = 0; + LONG count = 0; ThrowHrIfFailed(namespaceAliasesToStrip->get_length(&count)); ThrowErrorIf(Error::XmlError, (count > 1), "Only one IgnorableNamespaces attribute allowed"); std::vector aliasesToLookup; - for(long index=0; index < count; index++) + for(LONG index=0; index < count; index++) { // get the list of ignorable namespace aliases ComPtr node; ThrowHrIfFailed(namespaceAliasesToStrip->get_item(index, &node)); @@ -450,15 +450,15 @@ class MSXMLDom final : public ComClass Variant attributeValue; ThrowHrIfFailed(attribute->get_nodeValue(attributeValue.AddressOf())); ThrowErrorIf(Error::XmlError, (VT_NULL == attributeValue.Get().vt), "ignorable namespace alias has empty target namespace URI."); - std::wstring uri(reinterpret_cast(attributeValue.Get().bstrVal)); + std::wstring uri(attributeValue.Get().bstrVal); std::transform(uri.begin(), uri.end(), uri.begin(), ::tolower); // next we look for that uri against our namespace manager const auto& result = std::find(namespaces.begin(), namespaces.end(), uri.c_str()); if (result == namespaces.end()) { // the namespace specified is unknown to us. remove everything with the specified alias! std::wostringstream xPath; - xPath << L"//*[namespace-uri()='" << reinterpret_cast(attributeValue.Get().bstrVal) - << L"' or //@*[namespace-uri()='" << reinterpret_cast(attributeValue.Get().bstrVal) + xPath << L"//*[namespace-uri()='" << attributeValue.Get().bstrVal + << L"' or //@*[namespace-uri()='" << attributeValue.Get().bstrVal << L"']]"; Bstr query(xPath.str()); ComPtr ignorableNodes; @@ -479,7 +479,7 @@ class MSXMLDom final : public ComClass if (VARIANT_FALSE == success) { ThrowHrIfFailed(m_xmlDocument->get_parseError(&error)); } if (stripIgnorableNamespaces && nullptr == error.Get()) { - long readyState = 0; + LONG readyState = 0; ThrowHrIfFailed(m_xmlDocument->get_readyState(&readyState)); ThrowErrorIfNot(Error::Unexpected, (4 == readyState), "The document has not been completely loaded."); ThrowHrIfFailed(m_xmlDocument->validate(&error)); @@ -487,7 +487,7 @@ class MSXMLDom final : public ComClass if(error) { - long errorCode = 0, lineNumber = 0, columnNumber = 0; + LONG errorCode = 0, lineNumber = 0, columnNumber = 0; ThrowHrIfFailed(error->get_errorCode(&errorCode)); if (0 != errorCode) { @@ -504,13 +504,13 @@ class MSXMLDom final : public ComClass // XML into generic Xml errors and leave the full details in the log. if (UNDECLAREDPREFIX == errorCode || DECLARATION_NOTFOUND == errorCode) { // file is either invalid XML, or it's valid, but no schema was found for it. - errorCode = static_cast(Error::XmlFatal); + errorCode = static_cast(Error::XmlFatal); } else if (ELEMENT_EMPTY == errorCode || INVALID_CONTENT == errorCode) { // file is valid XML, but it failed according to the schema provided. - errorCode = static_cast(Error::XmlError); + errorCode = static_cast(Error::XmlError); } - ThrowErrorIf(errorCode, (true), message.str().c_str()); + ThrowErrorAndLog(errorCode, message.str().c_str()); } } } @@ -536,9 +536,9 @@ class MSXMLDom final : public ComClass ComPtr element = root.As(); ComPtr list = element->SelectNodes(query); - long count = 0; + LONG count = 0; ThrowHrIfFailed(list->get_length(&count)); - for(long index=0; index < count; index++) + for(LONG index=0; index < count; index++) { ComPtr node; ThrowHrIfFailed(list->get_item(index, &node)); @@ -571,7 +571,7 @@ class MSXMLFactory final : public ComClass ~MSXMLFactory() { if (m_CoInitialized) { CoUninitialize(); m_CoInitialized = false; } } - ComPtr CreateDomFromStream(XmlContentType footPrintType, const ComPtr& stream) override + ComPtr CreateDomFromStream(XmlContentType /*footPrintType*/, const ComPtr& stream) override { NamespaceManager emptyManager; diff --git a/src/msix/common/AppxFactory.cpp b/src/msix/common/AppxFactory.cpp index ad000dd08..783552ef3 100644 --- a/src/msix/common/AppxFactory.cpp +++ b/src/msix/common/AppxFactory.cpp @@ -97,6 +97,8 @@ namespace MSIX { auto zip = ComPtr::Make(outputStream); auto result = ComPtr::Make(self.Get(), zip, bundleVersion); *bundleWriter = result.Detach(); + #else + (void) bundleVersion; #endif return static_cast(Error::OK); } CATCH_RETURN(); @@ -119,6 +121,8 @@ namespace MSIX { ComPtr input(inputStream); auto result = ComPtr::Make(this, input); *manifestReader = result.Detach(); + #else + (void) inputStream; #endif return static_cast(Error::OK); } CATCH_RETURN(); @@ -175,7 +179,7 @@ namespace MSIX { ComPtr AppxFactory::GetResource(const std::string& resource) { // Short-circuit the case where there were no resources and throw not found immediately. - if (Resource::resourceLength <= 1) + if constexpr (Resource::resourceLength <= 1) { ThrowErrorAndLog(Error::FileNotFound, resource.c_str()); } diff --git a/src/msix/common/AppxManifestObject.cpp b/src/msix/common/AppxManifestObject.cpp index c4957e5f8..2baaa9904 100644 --- a/src/msix/common/AppxManifestObject.cpp +++ b/src/msix/common/AppxManifestObject.cpp @@ -29,51 +29,51 @@ namespace MSIX { // ALL THE TargetDeviceFamily ENTRIES MUST BE LOWER-CASE static const Entry targetDeviceFamilyList[] = { - Entry(u8"windows.universal", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.mobile", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.desktop", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.xbox", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.team", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.holographic", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.iot", MSIX_PLATFORM_WINDOWS10), - Entry(u8"windows.server", MSIX_PLATFORM_WINDOWS10), - Entry(u8"apple.ios.all", MSIX_PLATFORM_IOS), - Entry(u8"apple.ios.phone", MSIX_PLATFORM_IOS), - Entry(u8"apple.ios.tablet", MSIX_PLATFORM_IOS), - Entry(u8"apple.ios.tv", MSIX_PLATFORM_IOS), - Entry(u8"apple.ios.watch", MSIX_PLATFORM_IOS), - Entry(u8"apple.macos.all", MSIX_PLATFORM_MACOS), - Entry(u8"google.android.all", MSIX_PLATFORM_AOSP), - Entry(u8"google.android.phone", MSIX_PLATFORM_AOSP), - Entry(u8"google.android.tablet", MSIX_PLATFORM_AOSP), - Entry(u8"google.android.desktop", MSIX_PLATFORM_AOSP), - Entry(u8"google.android.tv", MSIX_PLATFORM_AOSP), - Entry(u8"google.android.watch", MSIX_PLATFORM_AOSP), - Entry(u8"msixcore.desktop", MSIX_PLATFORM_CORE), - Entry(u8"msixcore.server", MSIX_PLATFORM_CORE), - Entry(u8"linux.all", MSIX_PLATFORM_LINUX), - Entry(u8"web.edge.all", MSIX_PLATFORM_WEB), - Entry(u8"web.blink.all", MSIX_PLATFORM_WEB), - Entry(u8"web.chromium.all", MSIX_PLATFORM_WEB), - Entry(u8"web.webkit.all", MSIX_PLATFORM_WEB), - Entry(u8"web.safari.all", MSIX_PLATFORM_WEB), - Entry(u8"web.all", MSIX_PLATFORM_WEB), - Entry(u8"platform.all", static_cast(MSIX_PLATFORM_ALL)), + Entry("windows.universal", MSIX_PLATFORM_WINDOWS10), + Entry("windows.mobile", MSIX_PLATFORM_WINDOWS10), + Entry("windows.desktop", MSIX_PLATFORM_WINDOWS10), + Entry("windows.xbox", MSIX_PLATFORM_WINDOWS10), + Entry("windows.team", MSIX_PLATFORM_WINDOWS10), + Entry("windows.holographic", MSIX_PLATFORM_WINDOWS10), + Entry("windows.iot", MSIX_PLATFORM_WINDOWS10), + Entry("windows.server", MSIX_PLATFORM_WINDOWS10), + Entry("apple.ios.all", MSIX_PLATFORM_IOS), + Entry("apple.ios.phone", MSIX_PLATFORM_IOS), + Entry("apple.ios.tablet", MSIX_PLATFORM_IOS), + Entry("apple.ios.tv", MSIX_PLATFORM_IOS), + Entry("apple.ios.watch", MSIX_PLATFORM_IOS), + Entry("apple.macos.all", MSIX_PLATFORM_MACOS), + Entry("google.android.all", MSIX_PLATFORM_AOSP), + Entry("google.android.phone", MSIX_PLATFORM_AOSP), + Entry("google.android.tablet", MSIX_PLATFORM_AOSP), + Entry("google.android.desktop", MSIX_PLATFORM_AOSP), + Entry("google.android.tv", MSIX_PLATFORM_AOSP), + Entry("google.android.watch", MSIX_PLATFORM_AOSP), + Entry("msixcore.desktop", MSIX_PLATFORM_CORE), + Entry("msixcore.server", MSIX_PLATFORM_CORE), + Entry("linux.all", MSIX_PLATFORM_LINUX), + Entry("web.edge.all", MSIX_PLATFORM_WEB), + Entry("web.blink.all", MSIX_PLATFORM_WEB), + Entry("web.chromium.all", MSIX_PLATFORM_WEB), + Entry("web.webkit.all", MSIX_PLATFORM_WEB), + Entry("web.safari.all", MSIX_PLATFORM_WEB), + Entry("web.all", MSIX_PLATFORM_WEB), + Entry("platform.all", static_cast(MSIX_PLATFORM_ALL)), }; static const Entry capabilitiesList[] = { - Entry(u8"internetClient", APPX_CAPABILITY_INTERNET_CLIENT), - Entry(u8"internetClientServer", APPX_CAPABILITY_INTERNET_CLIENT_SERVER), - Entry(u8"privateNetworkClientServer", APPX_CAPABILITY_PRIVATE_NETWORK_CLIENT_SERVER), - Entry(u8"documentsLibrary", APPX_CAPABILITY_DOCUMENTS_LIBRARY), - Entry(u8"picturesLibrary", APPX_CAPABILITY_PICTURES_LIBRARY), - Entry(u8"videosLibrary", APPX_CAPABILITY_VIDEOS_LIBRARY), - Entry(u8"musicLibrary", APPX_CAPABILITY_MUSIC_LIBRARY), - Entry(u8"enterpriseAuthentication", APPX_CAPABILITY_ENTERPRISE_AUTHENTICATION), - Entry(u8"sharedUserCertificates", APPX_CAPABILITY_SHARED_USER_CERTIFICATES), - Entry(u8"removableStorage", APPX_CAPABILITY_REMOVABLE_STORAGE), - Entry(u8"appointments", APPX_CAPABILITY_APPOINTMENTS), - Entry(u8"contacts", APPX_CAPABILITY_CONTACTS), + Entry("internetClient", APPX_CAPABILITY_INTERNET_CLIENT), + Entry("internetClientServer", APPX_CAPABILITY_INTERNET_CLIENT_SERVER), + Entry("privateNetworkClientServer", APPX_CAPABILITY_PRIVATE_NETWORK_CLIENT_SERVER), + Entry("documentsLibrary", APPX_CAPABILITY_DOCUMENTS_LIBRARY), + Entry("picturesLibrary", APPX_CAPABILITY_PICTURES_LIBRARY), + Entry("videosLibrary", APPX_CAPABILITY_VIDEOS_LIBRARY), + Entry("musicLibrary", APPX_CAPABILITY_MUSIC_LIBRARY), + Entry("enterpriseAuthentication", APPX_CAPABILITY_ENTERPRISE_AUTHENTICATION), + Entry("sharedUserCertificates", APPX_CAPABILITY_SHARED_USER_CERTIFICATES), + Entry("removableStorage", APPX_CAPABILITY_REMOVABLE_STORAGE), + Entry("appointments", APPX_CAPABILITY_APPOINTMENTS), + Entry("contacts", APPX_CAPABILITY_CONTACTS), }; AppxManifestObject::AppxManifestObject(IMsixFactory* factory, const ComPtr& stream) : m_factory(factory), m_stream(stream) @@ -304,13 +304,13 @@ namespace MSIX { return static_cast(Error::OK); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE AppxManifestObject::GetDeviceCapabilities(IAppxManifestDeviceCapabilitiesEnumerator **deviceCapabilities) noexcept + HRESULT STDMETHODCALLTYPE AppxManifestObject::GetDeviceCapabilities(IAppxManifestDeviceCapabilitiesEnumerator **/*deviceCapabilities*/) noexcept { return static_cast(Error::NotImplemented); } // This method became deprecated as of Windows 8.1, use GetTargetDeviceFamilies instead. - HRESULT STDMETHODCALLTYPE AppxManifestObject::GetPrerequisite(LPCWSTR name, UINT64 *value) noexcept + HRESULT STDMETHODCALLTYPE AppxManifestObject::GetPrerequisite(LPCWSTR /*name*/, UINT64 */*value*/) noexcept { return static_cast(Error::NotImplemented); } diff --git a/src/msix/common/AppxManifestValidation.cpp b/src/msix/common/AppxManifestValidation.cpp index cc17d1fac..13781958d 100644 --- a/src/msix/common/AppxManifestValidation.cpp +++ b/src/msix/common/AppxManifestValidation.cpp @@ -47,7 +47,7 @@ namespace MSIX { { bool result = false; XmlVisitor visitor{ &result, - [](void* c, const MSIX::ComPtr& element) + [](void* c, const MSIX::ComPtr& /*element*/) { *reinterpret_cast(c) = true; return false; diff --git a/src/msix/common/Encoding.cpp b/src/msix/common/Encoding.cpp index 7e37d841d..6ac3c6408 100644 --- a/src/msix/common/Encoding.cpp +++ b/src/msix/common/Encoding.cpp @@ -186,7 +186,7 @@ namespace MSIX { namespace Encoding { // where wwww = uuuuu - 1 // //----------------------------------------------------------------------------- - void ValidateCodepoint(std::uint32_t codepoint, std::uint32_t sequenceSize) + void ValidateCodepoint(std::uint32_t codepoint, std::uint32_t /*sequenceSize*/) { // The valid range of Unicode code points is [U+0000, U+10FFFF]. DecodeFileName cannot generate a value larger // than 0x10FFFF: The "4 Byte sequence" section of code is responsible for the most significant change to the @@ -315,7 +315,7 @@ namespace MSIX { namespace Encoding { } ValidateCodepoint(codepoint, sequenceSize); - if (codepoint <= 0xFFFF) { result.push_back(codepoint); } + if (codepoint <= 0xFFFF) { result.push_back(static_cast(codepoint)); } else { // Because of the expected range of codepoints [0x010000, 0x10FFFF], the // subtraction never underflows. What you end up with is the 11 bits after @@ -323,9 +323,9 @@ namespace MSIX { namespace Encoding { // max for the codepoint is 0x10FFFF, the max for the 11 bits minus 0x1000 // is 0x3FF (and the minimum is 0). OR'ed with D800 gives the range // [0xD800, 0xDBFF] which is the range of the high surrogate. - wchar_t ch1 = ((codepoint & 0x00FC00) >> 10) | + wchar_t ch1 = static_cast(((codepoint & 0x00FC00) >> 10) | (((codepoint & 0x1F0000) - 0x010000) >> 10) | - 0x00D800; + 0x00D800); result.push_back(ch1); // Since the codepoint is AND'ed with 0x3FF (the bottom 10 bits of the // codepoint) and OR'ed with 0xDC00, the possible range is 0xDC00 through diff --git a/src/msix/common/Exceptions.cpp b/src/msix/common/Exceptions.cpp index 3fafd459d..ff209f8d7 100644 --- a/src/msix/common/Exceptions.cpp +++ b/src/msix/common/Exceptions.cpp @@ -24,7 +24,7 @@ FARPROC WINAPI MsixDelayLoadFailureHandler(unsigned /*dliNotify*/, PDelayLoadInf } ThrowErrorAndLog(HRESULT_FROM_WIN32(ERROR_PROC_NOT_FOUND), "Failed delayloading"); } -const PfnDliHook __pfnDliFailureHook2 = MsixDelayLoadFailureHandler; +PfnDliHook __pfnDliFailureHook2 = MsixDelayLoadFailureHandler; #endif namespace MSIX { diff --git a/src/msix/common/TimeHelpers.cpp b/src/msix/common/TimeHelpers.cpp index 11d3daabb..dfa3d1935 100644 --- a/src/msix/common/TimeHelpers.cpp +++ b/src/msix/common/TimeHelpers.cpp @@ -6,6 +6,7 @@ #include "TimeHelpers.hpp" #include +#include namespace MSIX { @@ -13,9 +14,11 @@ namespace MSIX { { // Convert system time to local time so the zip file item can have the same time of the zip archive when // it is shown in zip utility tools. + const auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - const auto localTime = std::localtime(&now); - Initialize(localTime); + struct tm localTime; + localtime_s(&localTime, &now); + Initialize(&localTime); } MsDosDateAndTime::MsDosDateAndTime(const std::tm* time) diff --git a/src/msix/common/ZipObject.cpp b/src/msix/common/ZipObject.cpp index 41abc468a..06a168180 100644 --- a/src/msix/common/ZipObject.cpp +++ b/src/msix/common/ZipObject.cpp @@ -497,15 +497,4 @@ void EndCentralDirectoryRecord::Read(const ComPtr& stream) } } -// Use for editing a package -ZipObject::ZipObject(const ComPtr& storageObject) -{ - auto other = reinterpret_cast(storageObject.Get()); - m_endCentralDirectoryRecord = other->m_endCentralDirectoryRecord; - m_zip64Locator = other->m_zip64Locator; - m_zip64EndOfCentralDirectory = other->m_zip64EndOfCentralDirectory; - m_centralDirectories = std::move(other->m_centralDirectories); - m_stream = std::move(m_stream); -} - } // namespace MSIX diff --git a/src/msix/msix.cpp b/src/msix/msix.cpp index f5de1b728..c1e49924c 100644 --- a/src/msix/msix.cpp +++ b/src/msix/msix.cpp @@ -147,6 +147,9 @@ MSIX_API HRESULT STDMETHODCALLTYPE CoCreateAppxBundleFactory( #if defined(WIN32) && defined(BUNDLE_SUPPORT) return CoCreateAppxBundleFactoryWithHeap(CoTaskMemAlloc, CoTaskMemFree, validationOption, applicabilityOptions, appxBundleFactory); #else + (VOID) applicabilityOptions; + (VOID) appxBundleFactory; + (VOID) validationOption; return static_cast(MSIX::Error::NotSupported); #endif } diff --git a/src/msix/pack/AppxPackageWriter.cpp b/src/msix/pack/AppxPackageWriter.cpp index fc47d4cb1..02e7c8f89 100644 --- a/src/msix/pack/AppxPackageWriter.cpp +++ b/src/msix/pack/AppxPackageWriter.cpp @@ -115,7 +115,7 @@ namespace MSIX { // IAppxPackageWriter3 HRESULT STDMETHODCALLTYPE AppxPackageWriter::AddPayloadFiles(UINT32 fileCount, - APPX_PACKAGE_WRITER_PAYLOAD_STREAM* payloadFiles, UINT64 memoryLimit) noexcept try + APPX_PACKAGE_WRITER_PAYLOAD_STREAM* payloadFiles, UINT64 /*memoryLimit*/) noexcept try { ThrowErrorIf(Error::InvalidState, m_state != WriterState::Open, "Invalid package writer state"); auto failState = MSIX::scope_exit([this] @@ -136,7 +136,7 @@ namespace MSIX { // IAppxPackageWriter3Utf8 HRESULT STDMETHODCALLTYPE AppxPackageWriter::AddPayloadFiles(UINT32 fileCount, - APPX_PACKAGE_WRITER_PAYLOAD_STREAM_UTF8* payloadFiles, UINT64 memoryLimit) noexcept try + APPX_PACKAGE_WRITER_PAYLOAD_STREAM_UTF8* payloadFiles, UINT64 /*memoryLimit*/) noexcept try { ThrowErrorIf(Error::InvalidState, m_state != WriterState::Open, "Invalid package writer state"); auto failState = MSIX::scope_exit([this] diff --git a/src/msix/pack/ZipObjectWriter.cpp b/src/msix/pack/ZipObjectWriter.cpp index 68e4f6a51..9a9c22e8a 100644 --- a/src/msix/pack/ZipObjectWriter.cpp +++ b/src/msix/pack/ZipObjectWriter.cpp @@ -37,28 +37,14 @@ namespace MSIX { { } - // This is used for editing a package (aka signing) - ZipObjectWriter::ZipObjectWriter(const ComPtr& storageObject) : ZipObject(storageObject) - { - // The storage object provided should had already initialize all the data. - ThrowErrorIfNot(Error::Zip64EOCDRecord, m_endCentralDirectoryRecord.GetIsZip64(), - "Editing non zip64 packages not supported"); - - // Move the stream at the start of central directory record so we can start overwritting. - // Central directory data in already in m_centralDirectories. - LARGE_INTEGER pos = {0}; - pos.QuadPart = m_zip64EndOfCentralDirectory.GetOffsetStartOfCD(); - ThrowHrIfFailed(m_stream->Seek(pos, StreamBase::Reference::START, nullptr)); - } - // IStorage - std::vector ZipObjectWriter::GetFileNames(FileNameOptions options) + std::vector ZipObjectWriter::GetFileNames(FileNameOptions /*options*/) { // TODO: implement NOTIMPLEMENTED; } - ComPtr ZipObjectWriter::GetFile(const std::string& fileName) + ComPtr ZipObjectWriter::GetFile(const std::string& /*fileName*/) { // TODO: implement NOTIMPLEMENTED; diff --git a/src/msix/unpack/ApplicabilityCommon.cpp b/src/msix/unpack/ApplicabilityCommon.cpp index e526372d0..cb0675975 100644 --- a/src/msix/unpack/ApplicabilityCommon.cpp +++ b/src/msix/unpack/ApplicabilityCommon.cpp @@ -27,9 +27,9 @@ namespace MSIX { // We've seen cases were uloc_toLanguageTag returns zh-CN. Add here any inconsistencies. // Some AppxBundleManifests have zh-CN, zh-TW, zh-HK as languages. static const Bcp47Entry bcp47List[] = { - Bcp47Entry(u8"zh-cn", u8"zh-Hans-CN"), - Bcp47Entry(u8"zh-hk", u8"zh-Hant-HK"), - Bcp47Entry(u8"zh-tw", u8"zh-Hant-TW"), + Bcp47Entry("zh-cn", "zh-Hans-CN"), + Bcp47Entry("zh-hk", "zh-Hant-HK"), + Bcp47Entry("zh-tw", "zh-Hant-TW"), }; Bcp47Tag::Bcp47Tag(const std::string& fullTag, bool allowPseudoLocale) diff --git a/src/msix/unpack/AppxBlockMapObject.cpp b/src/msix/unpack/AppxBlockMapObject.cpp index ae8d9d7f9..a93247a08 100644 --- a/src/msix/unpack/AppxBlockMapObject.cpp +++ b/src/msix/unpack/AppxBlockMapObject.cpp @@ -34,8 +34,8 @@ namespace MSIX { static Block GetBlock(const ComPtr& element, std::uint64_t fallbackSize) { Block result {0}; - auto sizeAttr = GetNumber(element, XmlAttributeName::Size, -1); - if (sizeAttr == -1) + auto sizeAttr = GetNumber(element, XmlAttributeName::Size, UINT64_MAX); + if (sizeAttr == UINT64_MAX) { result.blockSize = BLOCKMAP_BLOCK_SIZE; result.compressedSize = fallbackSize; @@ -140,7 +140,7 @@ namespace MSIX { return static_cast(Error::OK); } CATCH_RETURN(); - HRESULT STDMETHODCALLTYPE AppxBlockMapObject::GetHashMethod(IUri **hashMethod) noexcept + HRESULT STDMETHODCALLTYPE AppxBlockMapObject::GetHashMethod(IUri **/*hashMethod*/) noexcept { // Ultimately, this IUri object represents the HashMethod attribute in the blockmap: return static_cast(Error::NotImplemented); } diff --git a/src/msix/unpack/AppxPackageObject.cpp b/src/msix/unpack/AppxPackageObject.cpp index 07faee40a..8eebeead2 100644 --- a/src/msix/unpack/AppxPackageObject.cpp +++ b/src/msix/unpack/AppxPackageObject.cpp @@ -36,7 +36,7 @@ namespace MSIX { AppxPackageObject::AppxPackageObject(IMsixFactory* factory, MSIX_VALIDATION_OPTION validation, - MSIX_APPLICABILITY_OPTIONS applicabilityFlags, const ComPtr& container) : + MSIX_APPLICABILITY_OPTIONS /*applicabilityFlags*/, const ComPtr& container) : m_factory(factory), m_validation(validation), m_container(container) diff --git a/src/msix/unpack/InflateStream.cpp b/src/msix/unpack/InflateStream.cpp index b69dbfd38..ab45b2fa3 100644 --- a/src/msix/unpack/InflateStream.cpp +++ b/src/msix/unpack/InflateStream.cpp @@ -63,7 +63,7 @@ namespace MSIX { { case CompressionStatus::Error: self->Cleanup(); - ThrowErrorIfNot(Error::InflateCorruptData, false, "inflate failed unexpectedly."); + ThrowErrorAndLog(Error::InflateCorruptData, "inflate failed unexpectedly."); break; case CompressionStatus::Ok: case CompressionStatus::End: @@ -74,7 +74,7 @@ namespace MSIX { }), // State::READY_TO_INFLATE // State::READY_TO_COPY - InflateHandler([](InflateStream* self, void* buffer, ULONG countBytes) + InflateHandler([](InflateStream* self, _Out_cap_(countBytes) void* buffer, ULONG countBytes) { // Check if we're actually at the end of stream. if (self->m_fileCurrentPosition >= self->m_uncompressedSize) @@ -184,7 +184,7 @@ namespace MSIX { // Can't seek beyond the end of the uncompressed stream seekPosition.QuadPart = std::min(seekPosition.QuadPart, static_cast(m_uncompressedSize)); - if (seekPosition.QuadPart != m_seekPosition) + if (seekPosition.QuadPart != static_cast(m_seekPosition)) { m_seekPosition = seekPosition.QuadPart; // If the caller is trying to seek back to an earlier From f90c253a9d1ac32e1215444c7243f318b5cbdd9f Mon Sep 17 00:00:00 2001 From: Ryan Knuth Date: Mon, 28 Apr 2025 11:47:58 -0700 Subject: [PATCH 2/3] Missed file --- src/msix/PAL/Signature/Win32/SignatureValidator.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/msix/PAL/Signature/Win32/SignatureValidator.cpp b/src/msix/PAL/Signature/Win32/SignatureValidator.cpp index 16eed06a8..cc77b7c93 100644 --- a/src/msix/PAL/Signature/Win32/SignatureValidator.cpp +++ b/src/msix/PAL/Signature/Win32/SignatureValidator.cpp @@ -494,7 +494,6 @@ namespace MSIX bool SignatureValidator::Validate( - IMsixFactory* factory, IMsixFactory* /*factory*/, MSIX_VALIDATION_OPTION option, const ComPtr& stream, From ceeb7c5f488543cc67d2e33a46b12fea07eb039b Mon Sep 17 00:00:00 2001 From: Ryan Knuth Date: Wed, 30 Apr 2025 09:12:23 -0700 Subject: [PATCH 3/3] Bring over more changes --- src/inc/internal/BlockMapStream.hpp | 3 +++ src/inc/internal/Encoding.hpp | 3 +-- src/inc/internal/HashStream.hpp | 3 +++ src/inc/public/MsixErrors.hpp | 3 +++ src/makemsix/main.cpp | 1 + src/msix/common/Encoding.cpp | 1 - src/msix/common/TimeHelpers.cpp | 6 +++++- src/msix/msix.cpp | 6 +++--- src/msix/pack/XmlWriter.cpp | 2 +- src/msix/unpack/ApplicabilityCommon.cpp | 4 ++-- 10 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/inc/internal/BlockMapStream.hpp b/src/inc/internal/BlockMapStream.hpp index efb18198d..729e42b1a 100644 --- a/src/inc/internal/BlockMapStream.hpp +++ b/src/inc/internal/BlockMapStream.hpp @@ -3,7 +3,10 @@ // See LICENSE file in the project root for full license information. // #pragma once +#ifndef NOMINMAX #define NOMINMAX /* windows.h, or more correctly windef.h, defines min as a macro... */ +#endif + #include "MSIXWindows.hpp" #include "Exceptions.hpp" #include "StreamBase.hpp" diff --git a/src/inc/internal/Encoding.hpp b/src/inc/internal/Encoding.hpp index dcc42f476..6eb1d267a 100644 --- a/src/inc/internal/Encoding.hpp +++ b/src/inc/internal/Encoding.hpp @@ -5,7 +5,6 @@ #pragma once #include -#include namespace MSIX { namespace Encoding { @@ -13,6 +12,6 @@ namespace MSIX { namespace Encoding { std::string EncodeFileName(const std::string& fileName); std::string Base32Encoding(const std::vector& bytes); - std::vector GetBase64DecodedValue(const std::string& value); + std::vector GetBase64DecodedValue(const std::string& value); } /*Encoding */ } /* MSIX */ diff --git a/src/inc/internal/HashStream.hpp b/src/inc/internal/HashStream.hpp index d6faba7e3..87604df3a 100644 --- a/src/inc/internal/HashStream.hpp +++ b/src/inc/internal/HashStream.hpp @@ -3,7 +3,10 @@ // See LICENSE file in the project root for full license information. // #pragma once +#ifndef NOMINMAX #define NOMINMAX /* windows.h, or more correctly windef.h, defines min as a macro... */ +#endif + #include "MSIXWindows.hpp" #include "Exceptions.hpp" #include "StreamBase.hpp" diff --git a/src/inc/public/MsixErrors.hpp b/src/inc/public/MsixErrors.hpp index bf9ac9b8e..2510e0fee 100644 --- a/src/inc/public/MsixErrors.hpp +++ b/src/inc/public/MsixErrors.hpp @@ -6,7 +6,10 @@ #ifndef MSIX_MSIX_ERRORS__H #define MSIX_MSIX_ERRORS__H +#ifdef WIN32 #include +#endif + namespace MSIX { diff --git a/src/makemsix/main.cpp b/src/makemsix/main.cpp index 4cdf1652a..a823ca0f6 100644 --- a/src/makemsix/main.cpp +++ b/src/makemsix/main.cpp @@ -656,6 +656,7 @@ Command CreateBundleCommand() #pragma endregion // Defines the grammar of commands and each command's associated options, +#pragma warning(suppress: 4007) // Suppress 'main': must be '__cdecl' int main(int argc, char* argv[]) { std::cout << "Microsoft (R) makemsix version " << SDK_VERSION << std::endl; diff --git a/src/msix/common/Encoding.cpp b/src/msix/common/Encoding.cpp index 6ac3c6408..2f9a675dd 100644 --- a/src/msix/common/Encoding.cpp +++ b/src/msix/common/Encoding.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "Encoding.hpp" #include "Exceptions.hpp" diff --git a/src/msix/common/TimeHelpers.cpp b/src/msix/common/TimeHelpers.cpp index dfa3d1935..1eb0bd5f4 100644 --- a/src/msix/common/TimeHelpers.cpp +++ b/src/msix/common/TimeHelpers.cpp @@ -6,7 +6,7 @@ #include "TimeHelpers.hpp" #include -#include +#include namespace MSIX { @@ -17,7 +17,11 @@ namespace MSIX { const auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); struct tm localTime; +#ifdef WIN32 localtime_s(&localTime, &now); +#else + localtime_r(&now, &localTime); +#endif Initialize(&localTime); } diff --git a/src/msix/msix.cpp b/src/msix/msix.cpp index c1e49924c..dacc2598b 100644 --- a/src/msix/msix.cpp +++ b/src/msix/msix.cpp @@ -147,9 +147,9 @@ MSIX_API HRESULT STDMETHODCALLTYPE CoCreateAppxBundleFactory( #if defined(WIN32) && defined(BUNDLE_SUPPORT) return CoCreateAppxBundleFactoryWithHeap(CoTaskMemAlloc, CoTaskMemFree, validationOption, applicabilityOptions, appxBundleFactory); #else - (VOID) applicabilityOptions; - (VOID) appxBundleFactory; - (VOID) validationOption; + (void) applicabilityOptions; + (void) appxBundleFactory; + (void) validationOption; return static_cast(MSIX::Error::NotSupported); #endif } diff --git a/src/msix/pack/XmlWriter.cpp b/src/msix/pack/XmlWriter.cpp index cbaa3635b..033ccc67c 100644 --- a/src/msix/pack/XmlWriter.cpp +++ b/src/msix/pack/XmlWriter.cpp @@ -98,7 +98,7 @@ namespace MSIX { // and all #xD characters are replaced by void XmlWriter::WriteTextValue(const std::string& value) { - for(int i = 0; i < value.size(); i++) + for(size_t i = 0; i < value.size(); i++) { if (value[i] == '&') { diff --git a/src/msix/unpack/ApplicabilityCommon.cpp b/src/msix/unpack/ApplicabilityCommon.cpp index cb0675975..23015098e 100644 --- a/src/msix/unpack/ApplicabilityCommon.cpp +++ b/src/msix/unpack/ApplicabilityCommon.cpp @@ -57,8 +57,8 @@ namespace MSIX { auto position = found+1; found = bcp47Tag.find(delimiter, position); auto tag = bcp47Tag.substr(position, found - position); - auto maxTagLength = allowPseudoLocale ? 5 : 4; - ThrowErrorIf(Error::Unexpected, (tag.size() < 2 || tag.size() > maxTagLength), "Malformed Bcp47 tag"); + auto maxTagLength = allowPseudoLocale ? 5u : 4u; + ThrowErrorIf(Error::Unexpected, (tag.size() < 2u || tag.size() > maxTagLength), "Malformed Bcp47 tag"); if (tag.size() == 4) { // Script tag size is always 4 m_script = tag;