diff --git a/.gitignore b/.gitignore index 24dbac2..1f23342 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ priv *~ *.swp compile_commands.json +/.rebar/ diff --git a/rebar.config b/rebar.config index 7ecafcf..cbc3441 100644 --- a/rebar.config +++ b/rebar.config @@ -1,8 +1,8 @@ {erl_opts, [debug_info, warn_unused_vars, warn_shadow_vars, warn_unused_import]}. -{port_sources, ["c_src/*.cc", +{port_sources, ["c_src/*.cc", "c_src/snappy/*.cc"]}. {port_env, [ - {"CXXFLAGS", "$CXXFLAGS -DNDEBUG -std=c++11"}, + {"CXXFLAGS", "$CXXFLAGS -DNDEBUG -O3"}, {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)", "LDFLAGS", "$LDFLAGS -lstdc++"} ]}. diff --git a/test/snappy_tests.erl b/test/snappy_tests.erl index ac39c58..156e0e2 100644 --- a/test/snappy_tests.erl +++ b/test/snappy_tests.erl @@ -72,3 +72,14 @@ decompression() -> ?assertEqual({ok, BigData}, snappy:decompress(Compressed3)), ok. +can_compress_and_decompress_binary_that_triggers_corruption_with_o3_test() -> + % triggers a corruption when compiled with -O3, but not with -O0, + % on OTP25, 26, 27 at least *and* clang18, but not clang16. GCC to be tested. + % See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=282217 for background. + Doc =[<<"00000000-7fffffff">>], + {ok, C} = snappy:compress(erlang:term_to_binary(Doc)), + true = snappy:is_valid(C), + {ok, U} = snappy:decompress(C), + New = erlang:binary_to_term(U), + ?assertEqual(Doc, New), + ok.