Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into write-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fragglet committed Mar 27, 2024
2 parents 7558558 + c05d0ae commit 8a39059
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 42 deletions.
124 changes: 116 additions & 8 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,125 @@ name: Continuous Integration
on: [push, pull_request]

jobs:
build:

build_and_coverage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: autogen
run: ./autogen.sh
- uses: actions/checkout@v4
- name: configure
run: ./configure
run: |
LDFLAGS="$CFLAGS" ./autogen.sh \
--enable-coverage
- name: make
run: make
run: make -j
- name: make check
run: make check || (grep . test/*.log; false)
run: |
make -j check || (cat test/test-suite.log; false)
- name: Generate coverage reports
run: |
./gencov lib/*.c src/*.c
mkdir artifacts
tar cf - lib/*.gcov src/*.gcov | tar -C artifacts -xf -
- name: Upload coverage-annotated source files
uses: actions/upload-artifact@v1
with:
path: "artifacts"
name: coverage_reports

ubsan_build:
runs-on: ubuntu-latest
env:
CC: clang
# TODO: Add -fsanitize=address and memory too.
CFLAGS: "-fsanitize=undefined
-fno-omit-frame-pointer
-fno-sanitize-recover=all
-fno-sanitize=shift-base"

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update
sudo apt -q install valgrind
- name: configure
run: |
LDFLAGS="$CFLAGS" ./autogen.sh
- name: make check
run: |
make -j check || (cat test/test-suite.log; false)
windows_x86_build:
runs-on: windows-latest

defaults:
run:
shell: msys2 {0}

steps:
- name: Setup msys2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW32
update: true
install: base-devel git autoconf automake libtool groff zip dos2unix mingw-w64-i686-gcc
- uses: actions/checkout@v4
- name: Find Git version
id: version
run: |
export VERSION=$(git rev-parse --short HEAD)
echo "VERSION=$VERSION-win32" >> $GITHUB_OUTPUT
# TODO: --disable-shared is here because pkg/win32 doesn't package the dll..
- name: configure
run: ./autogen.sh --disable-shared --host=i686-w64-mingw32
- name: make
run: make -j
# TODO: Tests are not currently run on Windows
- name: Make windows package
run: |
cd pkg/win32
make
- name: Upload build
uses: actions/upload-artifact@v1
with:
path: "pkg/win32/staging"
name: lhasa-${{steps.version.outputs.VERSION}}

windows_x64_build:
runs-on: windows-latest

defaults:
run:
shell: msys2 {0}

steps:
- name: Setup msys2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: base-devel git autoconf automake libtool groff zip dos2unix mingw-w64-x86_64-gcc
- uses: actions/checkout@v4
- name: Find Git version
id: version
run: |
export VERSION=$(git rev-parse --short HEAD)
echo "VERSION=$VERSION-win64" >> $GITHUB_OUTPUT
# TODO: --disable-shared is here because pkg/win64 doesn't package the dll..
- name: configure
run: ./autogen.sh --disable-shared --host=x86_64-w64-mingw32
- name: make
run: make -j
# TODO: Tests are not currently run on Windows
# TODO: win64 packaging requires updated pkg directory
#- name: Make windows package
# run: |
# cd pkg/win64
# make
#- name: Upload build
# uses: actions/upload-artifact@v1
# with:
# path: "pkg/win64/staging"
# name: lhasa-${{steps.version.outputs.VERSION}}
2 changes: 2 additions & 0 deletions .lvimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
" Local vimrc configuration file. Install the localvimrc.vim vim script.
setlocal tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab cindent
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ Library:
* Correctly handle LHmelt backwards directory ordering.
* Add test archives generated by:
* Microsoft LZH folder add-in for Windows (if possible?)
* UNLHA32
* Decompressors for obscure algorithms:
* -lh2-, -lh3- (experimental LHA?)
* LHark -lh7- (modified -lh5-)
* -lx1- (unlha32 obscure/experimental?)

Command line tool:
Expand Down
9 changes: 1 addition & 8 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#!/bin/sh

mkdir -p autotools
autoreconf -fi && ./configure "$@"

libtoolize || glibtoolize
aclocal
autoheader
automake -a
autoconf
automake -a

./configure $@
12 changes: 11 additions & 1 deletion doc/lha.1
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ Extract the contents of \fBfoobar.lzh\fR to \fB/tmp\fR, overwriting any
existing files found there, and suppressing normal output (similar to
how other Unix tools such as \fBcp\fR(1) or \fBtar\fR(1) act silently
by default).
.SH WWW
.UR https://fragglet.github.io/lhasa
.UE
.SH BUG REPORTS
Bugs can be reported to the GitHub issue tracker:
.UR https://github.com/fragglet/lhasa
.UE
.SH SEE ALSO
\fBunzip\fR(1), \fBtar\fR(1), \fBgzip\fR(1), \fBbzip2\fR(1),
\fBxz\fR(1), \fBlzip\fR(1)
Expand Down Expand Up @@ -187,7 +194,10 @@ The tool does not currently do text format conversion for non-ASCII
filenames when listing the contents of archives. Non-ASCII characters
are replaced by a question mark.
.SH AUTHOR
Lhasa was written and is maintained by Simon Howard.
Lhasa was written and is maintained by
.MT [email protected]
Simon Howard
.ME .
.SH COPYRIGHT
Copyright \(co 2011-2023 Simon Howard.
.PP
Expand Down
10 changes: 5 additions & 5 deletions gencov
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2011, 2012, Simon Howard
#
Expand Down Expand Up @@ -70,11 +70,11 @@ def gcov(filename):
return results

def format_output(filename, stats):
print " %-35s%7s%7s%7s%7s" % ((filename, ) + stats)
print(" %-35s%7s%7s%7s%7s" % ((filename, ) + stats))

print
print()
format_output("Filename", ("Percent", "Uncov", "Cov", "Total"))
print " " + ("-" * 65)
print(" " + ("-" * 65))

for filename in sorted(sys.argv[1:]):
gcno = filename.replace(".c", ".gcno")
Expand Down Expand Up @@ -111,4 +111,4 @@ for filename in sorted(sys.argv[1:]):
if subfile != filename:
format_output(" -> " + subfile, results[subfile])

print
print()
1 change: 1 addition & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ liblhasatest_a_SOURCES=$(SRC) $(HEADER_FILES)

liblhasa_la_CFLAGS=$(MAIN_CFLAGS)
liblhasa_la_SOURCES=$(SRC) $(HEADER_FILES)
liblhasa_la_LDFLAGS=-no-undefined

clean-local:
rm -f *.gcno *.gcda *.c.gcov
17 changes: 7 additions & 10 deletions lib/bit_stream_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ static int peek_bits(BitStreamReader *reader,
unsigned int n)
{
uint8_t buf[4];
unsigned int fill_bytes;
size_t bytes;
size_t bytes, i;

if (n == 0) {
return 0;
Expand All @@ -74,11 +73,10 @@ static int peek_bits(BitStreamReader *reader,

// Maximum number of bytes we can fill?

fill_bytes = (32 - reader->bits) / 8;
const unsigned int fill_bytes = (32 - reader->bits) / 8;

// Read from input and fill bit_buffer.

memset(buf, 0, sizeof(buf));
bytes = reader->callback(buf, fill_bytes,
reader->callback_data);

Expand All @@ -88,12 +86,11 @@ static int peek_bits(BitStreamReader *reader,
return -1;
}

reader->bit_buffer |= (uint32_t) buf[0] << (24 - reader->bits);
reader->bit_buffer |= (uint32_t) buf[1] << (16 - reader->bits);
reader->bit_buffer |= (uint32_t) buf[2] << (8 - reader->bits);
reader->bit_buffer |= (uint32_t) buf[3];

reader->bits += bytes * 8;
for (i = 0; i < bytes; i++) {
reader->bit_buffer |=
(uint32_t) buf[i] << (24 - reader->bits);
reader->bits += 8;
}
}

return (signed int) (reader->bit_buffer >> (32 - n));
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ SOURCE_FILES= \
safe.c safe.h

lha_SOURCES=$(SOURCE_FILES)
lha_CFLAGS=$(MAIN_CFLAGS) -I$(top_builddir)/lib/public -I$(top_builddir)
lha_CFLAGS=$(MAIN_CFLAGS) -I$(top_builddir)/lib/public -I$(top_builddir) -I$(top_srcdir)/lib/public -I$(top_srcdir)
lha_LDADD=$(top_builddir)/lib/liblhasa.la

test_lha_SOURCES=$(SOURCE_FILES)
test_lha_CFLAGS=$(TEST_CFLAGS) -I$(top_builddir)/lib/public -I$(top_builddir)
test_lha_CFLAGS=$(TEST_CFLAGS) -I$(top_builddir)/lib/public -I$(top_builddir) -I$(top_srcdir)/lib/public -I$(top_srcdir)
test_lha_LDADD=$(top_builddir)/lib/liblhasatest.a

write_test_SOURCES=write_test.c
Expand Down
1 change: 1 addition & 0 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ static int extract_archived_file(LHAReader *reader,
// No need to extract directories if use_path is disabled.

if (!options->use_path && is_dir) {
free(filename);
return 1;
}

Expand Down
11 changes: 7 additions & 4 deletions test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

AM_CFLAGS=$(TEST_CFLAGS) -I$(top_builddir)/lib/public -I$(top_builddir) -g
AM_CFLAGS=$(TEST_CFLAGS) -I$(top_builddir)/lib/public -I$(top_builddir) -g -I$(top_srcdir)/lib/public -I$(top_srcdir)
LDADD=$(top_builddir)/lib/liblhasatest.a libtestframework.a

COMPILED_TESTS= \
Expand All @@ -26,10 +26,13 @@ EXTRA_DIST= \
TESTS=$(COMPILED_TESTS) $(UNCOMPILED_TESTS)

EXTRA_PROGRAMS=fuzzer ghost-tester
check_PROGRAMS=$(COMPILED_TESTS) \
SUPPORT_COMMANDS = \
dump-headers decompress-crc build-arch string-replace
check_PROGRAMS=$(COMPILED_TESTS) $(SUPPORT_COMMANDS)
check_LIBRARIES=libtestframework.a

$(TEST_LOGS): $(TESTS) $(SUPPORT_COMMANDS) ../src/test-lha

libtestframework_a_SOURCES= \
crc32.c crc32.h

Expand All @@ -49,9 +52,9 @@ check-prerun:

# Display coverage summary after running tests.

check: check-postrun
check: report-coverage

check-postrun:
report-coverage: check-am
@cd $(top_builddir); ./gencov lib/*.c src/*.c

endif
Expand Down
2 changes: 0 additions & 2 deletions test/ghost-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ static uint32_t generate_archive(char *out_filename, char *type,
size_t buf_len;
uint16_t crc16;
uint32_t crc32;
unsigned int skip_len;

skip_len = COMPRESSED_DATA_LEN;
buf_len = COMPRESSED_DATA_LEN + MIN_HEADER_LEN + strlen(filename);

buf = malloc(buf_len);
Expand Down
2 changes: 2 additions & 0 deletions test/string-replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ int main(int argc, char *argv[])
i++;
}
}

free(buf);
return 0;
}

1 change: 1 addition & 0 deletions test/test-basic-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static void check_decode_for(char *filename)
decoder = lha_basic_reader_decode(reader);
assert(decoder != NULL);
lha_decoder_free(decoder);
lha_basic_reader_free(reader);
lha_input_stream_free(stream);
}

Expand Down
3 changes: 3 additions & 0 deletions test/test-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ static void test_progress_for_file(DecoderTestData *file)

assert(progress.last_pos == progress.total);
assert(progress.calls == 1 + progress.total);

lha_decoder_free(decoder);
free(data);
}

static void test_progress_feedback(void)
Expand Down

0 comments on commit 8a39059

Please sign in to comment.