I want to use bzip2 in a c++ project I'm working on so before starting to use it everywhere I wanted to do as quick test. The test simply opens a file then writes some data into it and then closes the file. On Linux the code below works fine and does exactly what I would expect but on Windows I get a 0xc0000409(STATUS_STACK_BUFFER_OVERRUN) exception when calling BZ2_bzWriteClose. On Windows I installed the library using the bzip2:x86-windows vcpkg package. I am using the msvc compiler from vs2019.
I'm not sure why this happens and have no idea how to resolve this problem.
Code sample(I ommitted the error handling):
int bzError;
FILE* fp = fopen("test.bz2", "wb");
BZFILE *bzFile = BZ2_bzWriteOpen(&bzError, fp, 9, 0, 0);
vector<char> content = {'a', 'm', 'g', 'd', 'z'};
char* buffer = content.data();
int size = content.size();
BZ2_bzWrite(&bzError, bzFile, buffer, size);
BZ2_bzWriteClose(&bzError, bzFile, 0, nullptr, nullptr);
fclose(fp);
User contributions licensed under CC BY-SA 3.0