]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: avoid undefined behaviour in float division by 0.0
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Nov 2017 12:11:35 +0000 (13:11 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Nov 2017 20:34:50 +0000 (21:34 +0100)
Coverity says that's undefined. I'm pretty sure we always would get a nan, but
let's avoid (formally) undefined behaviour since that can cause compilers to do
strange things.

src/journal/compress.c

index a659459e496aff7005bfc902a4332dd10c5f9356..92eb3874fd05807409866ee609d94634770b4020 100644 (file)
@@ -667,7 +667,7 @@ int decompress_stream_lz4(int in, int out, uint64_t max_bytes) {
 
         log_debug("LZ4 decompression finished (%zu -> %zu bytes, %.1f%%)",
                   total_in, total_out,
-                  (double) total_out / total_in * 100);
+                  total_in > 0 ? (double) total_out / total_in * 100 : 0.0);
  cleanup:
         munmap(src, st.st_size);
         return r;