Skip to content

Commit 98a2ee0

Browse files
committed
process_zlib(): fix MSVC warning conversion from 'size_t' to 'uInt'
Since we use the `/WX` (treat warning as errors) option, this warning currently blocks the build on Windows. This is the relevant excerpt from the CI log: ``` ClCompile: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\bin\HostX64\x64\CL.exe /c /ID:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime\build /ID:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime /Zi /nologo /W4 /WX /diagnostics:column /Od /Ob0 /D _WINDLL /D _MBCS /D WIN32 /D _WINDOWS /D KS_ZLIB /D KS_STR_ENCODING_WIN32API /D "CMAKE_INTDIR=\"Debug\"" /D kaitai_struct_cpp_stl_runtime_EXPORTS /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"kaitai_struct_cpp_stl_runtime.dir\Debug\\" /Fd"kaitai_struct_cpp_stl_runtime.dir\Debug\vc143.pdb" /external:W0 /Gd /TP /errorReport:queue /external:I "C:/vcpkg/installed/x64-windows/include" D:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime\kaitai\kaitaistream.cpp kaitaistream.cpp D:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime\kaitai\kaitaistream.cpp(686,32): error C2220: the following warning is treated as an error [D:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime\build\kaitai_struct_cpp_stl_runtime.vcxproj] D:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime\kaitai\kaitaistream.cpp(686,32): warning C4267: '=': conversion from 'size_t' to 'uInt', possible loss of data [D:\a\kaitai_struct_cpp_stl_runtime\kaitai_struct_cpp_stl_runtime\build\kaitai_struct_cpp_stl_runtime.vcxproj] ``` See also https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267?view=msvc-170
1 parent 957829c commit 98a2ee0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kaitai/kaitaistream.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,13 @@ std::string kaitai::kstream::process_zlib(std::string data) {
683683
throw std::runtime_error("process_zlib: inflateInit error");
684684

685685
strm.next_in = src_ptr;
686-
strm.avail_in = data.length();
686+
if (data.length() > std::numeric_limits<uInt>::max()) {
687+
throw std::length_error(
688+
"process_zlib: input is " + to_string(data.length()) + " bytes long, which exceeds"
689+
" the maximum supported length of " + to_string(std::numeric_limits<uInt>::max()) + " bytes"
690+
);
691+
}
692+
strm.avail_in = static_cast<uInt>(data.length());
687693

688694
unsigned char outbuffer[ZLIB_BUF_SIZE];
689695
std::string outstring;

0 commit comments

Comments
 (0)