shithub: sox

Download patch

ref: 6e278eeef31bcbdf84ce4a14c32cdadee4164871
parent: 021c7886e4ecfe58022848aa3f4877e1986e3089
author: Mans Rullgard <mans@mansr.com>
date: Thu Aug 20 20:39:04 EDT 2020

formats: clarify setting of reverse_bytes

Factor out repeated conditions and merge the resulting if statement
with the following one.  This makes the intent clearer and silences
a flurry of warnings from clang.

--- a/src/formats.c
+++ b/src/formats.c
@@ -302,22 +302,26 @@
 
 static void set_endiannesses(sox_format_t * ft)
 {
-  if (ft->encoding.opposite_endian)
-    ft->encoding.reverse_bytes = (ft->handler.flags & SOX_FILE_ENDIAN)?
-      !(ft->handler.flags & SOX_FILE_ENDBIG) != MACHINE_IS_BIGENDIAN : sox_true;
-  else if (ft->encoding.reverse_bytes == sox_option_default)
-    ft->encoding.reverse_bytes = (ft->handler.flags & SOX_FILE_ENDIAN)?
-      !(ft->handler.flags & SOX_FILE_ENDBIG) == MACHINE_IS_BIGENDIAN : sox_false;
+  if (ft->handler.flags & SOX_FILE_ENDIAN) {
+    sox_bool file_is_bigendian = !(ft->handler.flags & SOX_FILE_ENDBIG);
 
+    if (ft->encoding.opposite_endian) {
+      ft->encoding.reverse_bytes = file_is_bigendian != MACHINE_IS_BIGENDIAN;
+      lsx_report("`%s': overriding file-type byte-order", ft->filename);
+    } else if (ft->encoding.reverse_bytes == sox_option_default) {
+      ft->encoding.reverse_bytes = file_is_bigendian == MACHINE_IS_BIGENDIAN;
+    }
+  } else {
+    if (ft->encoding.opposite_endian) {
+      ft->encoding.reverse_bytes = sox_option_yes;
+      lsx_report("`%s': overriding machine byte-order", ft->filename);
+    } else if (ft->encoding.reverse_bytes == sox_option_default) {
+      ft->encoding.reverse_bytes = sox_option_no;
+    }
+  }
+
   /* FIXME: Change reports to suitable warnings if trying
    * to override something that can't be overridden. */
-
-  if (ft->handler.flags & SOX_FILE_ENDIAN) {
-    if (ft->encoding.reverse_bytes == (sox_option_t)
-        (!(ft->handler.flags & SOX_FILE_ENDBIG) != MACHINE_IS_BIGENDIAN))
-      lsx_report("`%s': overriding file-type byte-order", ft->filename);
-  } else if (ft->encoding.reverse_bytes == sox_option_yes)
-    lsx_report("`%s': overriding machine byte-order", ft->filename);
 
   if (ft->encoding.reverse_bits == sox_option_default)
     ft->encoding.reverse_bits = !!(ft->handler.flags & SOX_FILE_BIT_REV);