Fixed shift direction for crc32sum() (#109)
* Fixed shift direction for crc32sum() ref. #105 ref. commit 7a8d35b161403d2c873abb6cbef74deaa18354cd * Add a `.bz3` reference file to test The `examples/shakespeare.txt.bz3` file was created by the following command ```console % ./bzip3 -e -b 4 < examples/shakespeare.txt > examples/shakespeare.txt.bz3 ``` At this time bzip3 is version 1.1.0 and running on FreeBSD 13.2 amd64.
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 25aa18f..573f295 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -48,12 +48,18 @@ jobs:
name: bzip3-${{ github.sha }}
- name: Extract source package
run: tar --strip-components=1 -xf bzip3-${{ github.sha}}.tar.gz
+ - name: Fetch examples
+ run: |
+ mkdir examples
+ cd examples
+ wget https://github.com/kspalaiologos/bzip3/raw/${{ github.sha }}/examples/shakespeare.txt \
+ https://github.com/kspalaiologos/bzip3/raw/${{ github.sha }}/examples/shakespeare.txt.bz3
- name: Configure
run: ./configure CC=${{ matrix.compiler }} --${{ matrix.feature }}
- name: Make
run: make
- name: Check
- run: make roundtrip
+ run: make roundtrip test
build-archs:
name: Build Matrix for non-x86 architectures (Debian Stretch)
@@ -72,6 +78,12 @@ jobs:
name: bzip3-${{ github.sha }}
- name: Extract source package
run: tar --strip-components=1 -xf bzip3-${{ github.sha}}.tar.gz
+ - name: Fetch examples
+ run: |
+ mkdir examples
+ cd examples
+ wget https://github.com/kspalaiologos/bzip3/raw/${{ github.sha }}/examples/shakespeare.txt \
+ https://github.com/kspalaiologos/bzip3/raw/${{ github.sha }}/examples/shakespeare.txt.bz3
- uses: uraimo/run-on-arch-action@v2
name: Run in the container
with:
@@ -86,7 +98,7 @@ jobs:
run: |
cd /bzip3
./configure CC=${{ matrix.compiler }} --${{ matrix.feature }} --disable-arch-native --disable-link-time-optimization
- make && make roundtrip
+ make && make roundtrip test
build-archs-ubuntu:
name: Build Matrix for non-x86 architectures (Ubuntu Latest)
needs: [ dist ]
@@ -104,6 +116,12 @@ jobs:
name: bzip3-${{ github.sha }}
- name: Extract source package
run: tar --strip-components=1 -xf bzip3-${{ github.sha}}.tar.gz
+ - name: Fetch examples
+ run: |
+ mkdir examples
+ cd examples
+ wget https://github.com/kspalaiologos/bzip3/raw/${{ github.sha }}/examples/shakespeare.txt \
+ https://github.com/kspalaiologos/bzip3/raw/${{ github.sha }}/examples/shakespeare.txt.bz3
- uses: uraimo/run-on-arch-action@v2
name: Run in the container
with:
@@ -118,7 +136,7 @@ jobs:
run: |
cd /bzip3
./configure CC=${{ matrix.compiler }} --${{ matrix.feature }} --disable-arch-native --disable-link-time-optimization
- make && make roundtrip
+ make && make roundtrip test
cmake:
name: Build with CMake
diff --git a/Makefile.am b/Makefile.am
index c2bed82..ad02e63 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -77,3 +77,7 @@ roundtrip: $(BZIP3)
./$(BZIP3) -v -d $(builddir)/LICENSE.bz3 $(builddir)/LICENSE2
cmp $(srcdir)/LICENSE $(builddir)/LICENSE2
-command -v md5sum >/dev/null 2>&1 && md5sum $(builddir)/LICENSE.bz3
+
+.PHONY: test
+test: $(BZIP3)
+ ./$(BZIP3) -d < $(srcdir)/examples/shakespeare.txt.bz3 | cmp - $(srcdir)/examples/shakespeare.txt
diff --git a/examples/shakespeare.txt.bz3 b/examples/shakespeare.txt.bz3
new file mode 100644
index 0000000..bae6e2e
Binary files /dev/null and b/examples/shakespeare.txt.bz3 differ
diff --git a/src/libbz3.c b/src/libbz3.c
index 374e24c..15c327a 100644
--- a/src/libbz3.c
+++ b/src/libbz3.c
@@ -61,7 +61,7 @@ static const u32 crc32Table[256] = {
};
static u32 crc32sum(u32 crc, u8 * RESTRICT buf, size_t size) {
- while (size--) crc = crc32Table[((crc >> 24) ^ *(buf++)) & 0xff] ^ (crc << 8);
+ while (size--) crc = crc32Table[((u8)crc ^ *(buf++)) & 0xff] ^ (crc >> 8);
return crc;
}
