Skip to content

Commit 8410964

Browse files
authored
Merge pull request #6 from mockingbirdnest/Alignment
Unaligned loads are UB
2 parents f6a0152 + a6e462e commit 8410964

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
UNAME_S := $(shell uname -s)
22

33
CXX := clang++
4+
# Add -fsanitize=undefined for UBSAN.
45
COMPILER_OPTIONS := \
56
-std=c++1z -stdlib=libc++ -O3 -g \
67
-fPIC -fexceptions -ferror-limit=1 -fno-omit-frame-pointer \
78
-Wall -Wpedantic \
9+
-DGIPFELI_NO_UNALIGNED \
810
-DNDEBUG -Iinclude
911

1012
TEST_TRANSLATION_UNITS := $(wildcard */*_test.cc)
@@ -16,11 +18,17 @@ ifeq ($(UNAME_S),Darwin)
1618
COMPILER_OPTIONS += -mmacosx-version-min=10.11 -arch x86_64
1719
endif
1820

19-
all: $(LIBRARY_OBJECTS)
21+
all: library
22+
23+
library: $(LIBRARY_OBJECTS)
2024
ar -rcs libgipfeli.a $^
2125

2226
clean:
23-
rm -f src/*.o
27+
rm -f src/*.o *.a gipfeli_test
28+
29+
test: $(TEST_OBJECTS) library
30+
$(CXX) -o gipfeli_test $(TEST_OBJECTS) $(COMPILER_OPTIONS) -L. -lgipfeli -lsupc++ -lc++
31+
2432

2533
%.o: %.cc
2634
$(CXX) -c -o $@ $< $(COMPILER_OPTIONS)

src/gipfeli_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,24 @@ bool TestFile(const string& label, const string& filename,
9393
string uncompressed;
9494
ResetTimer();
9595
bool success = compressor->Uncompress(compressed, &uncompressed);
96+
if (!success) {
97+
cout << "Uncompress failed\n";
98+
}
9699
*uncompression_time = GetElapsedTime();
97100

101+
if (original.size() == uncompressed.size()) {
102+
for (size_t i = 0; i < original.size(); ++i) {
103+
if (original[i] != uncompressed[i]) {
104+
cout << "Difference at position " << i << " of " << original.size()
105+
<< ", " << original[i] << " vs " << uncompressed[i] << "\n";
106+
break;
107+
}
108+
}
109+
} else {
110+
cout << "Size mismatch: " << original.size() << " vs. "
111+
<< uncompressed.size() << "\n";
112+
}
113+
98114
return success && (original == uncompressed);
99115
}
100116

0 commit comments

Comments
 (0)