Skip to content

Commit

Permalink
Upgrade cmake to 3.17
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- authored and prot0man committed Jan 17, 2024
1 parent 0b8109e commit 7c1646b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
cmake --build build
tree -sha build
- name: Test
run: ASAN_OPTIONS=detect_leaks=0 LSAN_OPTIONS=verbosity=1:log_threads=1 cmake --build build --target test
run: |
cd build
ASAN_OPTIONS=detect_leaks=0 LSAN_OPTIONS=verbosity=1:log_threads=1 CTEST_OUTPUT_ON_FAILURE=1 ctest -VV --output-on-failure
macos:
runs-on: macos-latest
Expand All @@ -33,7 +35,9 @@ jobs:
cmake --build build
tree -sha build
- name: Test
run: cmake --build build --target test
run: |
cd build
CTEST_OUTPUT_ON_FAILURE=1 ctest -VV --output-on-failure
# freebsd:
# runs-on: macos-latest
Expand Down Expand Up @@ -63,7 +67,7 @@ jobs:
- name: Test
run: |
cd build
ctest -VV -C "Debug"
ctest -VV -C "Debug" --output-on-failure
windows-mingw:
runs-on: "windows-latest"
Expand All @@ -76,4 +80,6 @@ jobs:
cmake --build build
tree /a /f build
- name: Test
run: cmake --build build --target test
run: |
cd build
ctest -VV -C "Debug" --output-on-failure
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.17)

project(zip
LANGUAGES C
Expand Down
19 changes: 14 additions & 5 deletions src/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,16 @@ static int zip_entry_finalize(struct zip_t *zip,
const ssize_t n) {

ssize_t i = 0;
mz_uint64 *local_header_ofs_array = (mz_uint64 *)calloc(n, sizeof(mz_uint64));
if (!local_header_ofs_array) {
return ZIP_EOOMEM;
}

if(n == 0) {
return 0;
}

mz_uint64 *local_header_ofs_array = (mz_uint64 *)calloc(n, sizeof(mz_uint64));
if (!local_header_ofs_array) {
return ZIP_EOOMEM;
}

for (i = 0; i < n; ++i) {
local_header_ofs_array[i] = entry_mark[i].m_local_header_ofs;
ssize_t index = zip_sort(local_header_ofs_array, i);
Expand Down Expand Up @@ -1843,7 +1844,15 @@ struct zip_t *zip_stream_openwitherror(const char *stream, size_t size,
// for modes 'd' and 'w', would be better to use mz_zip_reader_init_writer, but there's no clean
// way to load the existing stream with that.
if ((stream != NULL) && (size > 0) && (mode == 'r' || mode == 'd' || mode == 'w')) {
if (!mz_zip_reader_init_mem(&(zip->archive), stream, size, 0)) {
uint8_t *stream_copy = (uint8_t *)malloc(size);

if(!stream_copy) {
*errnum = ZIP_EOOMEM;
goto cleanup;
}
memcpy(stream_copy, stream, size);

if (!mz_zip_reader_init_mem(&(zip->archive), stream_copy, size, 0)) {
*errnum = ZIP_ERINIT;
goto cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.17)

find_package(Sanitizers)

Expand Down
7 changes: 5 additions & 2 deletions test/test_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ MU_TEST(test_entries_delete_stream) {
zdata = (uint8_t *)malloc(zsize);
mu_check(zdata != NULL);

rc = fread(zdata, zsize, 1, fh);
rc = fread(zdata, sizeof(uint8_t), zsize, fh);
mu_check(rc >= 1);

fclose(fh);
Expand All @@ -424,10 +424,13 @@ MU_TEST(test_entries_delete_stream) {
zip_stream_copy(zip, (void **)&modified_zdata, &zsize);
mu_check(modified_zdata != NULL);

zip_stream_close(zip);
free(zdata);
zdata = NULL;

// Note that zip_stream_close will free the zdata passed in zip_stream_open
zip_stream_close(zip);
zdata = NULL;

zip = zip_stream_open(modified_zdata, zsize, 0, 'r');
mu_check(zip != NULL);

Expand Down

0 comments on commit 7c1646b

Please sign in to comment.