pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/audio/libaudiofile libaudiofile: fix the second UB in ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5fba4f5be29e
branches:  trunk
changeset: 356118:5fba4f5be29e
user:      maya <maya%pkgsrc.org@localhost>
date:      Mon Dec 19 00:14:43 2016 +0000

description:
libaudiofile: fix the second UB in the same line of code, cstatic which
isn't actually a cstatic. switch to just defining it in the accessor.
GCC optimized this UB away leading to an undefined reference in the builds.

Also use a function which is right for int32 too (same as upstream)

Thanks joerg for the help

diffstat:

 audio/libaudiofile/distinfo                                          |   4 +-
 audio/libaudiofile/patches/patch-libaudiofile_modules_SimpleModule.h |  35 ++++++++-
 2 files changed, 32 insertions(+), 7 deletions(-)

diffs (64 lines):

diff -r 65b9ba475656 -r 5fba4f5be29e audio/libaudiofile/distinfo
--- a/audio/libaudiofile/distinfo       Sun Dec 18 23:40:22 2016 +0000
+++ b/audio/libaudiofile/distinfo       Mon Dec 19 00:14:43 2016 +0000
@@ -1,8 +1,8 @@
-$NetBSD: distinfo,v 1.28 2016/12/18 23:40:22 maya Exp $
+$NetBSD: distinfo,v 1.29 2016/12/19 00:14:43 maya Exp $
 
 SHA1 (audiofile-0.3.6.tar.gz) = 3aba3ef724b1b5f88cfc20ab9f8ce098e6c35a0e
 RMD160 (audiofile-0.3.6.tar.gz) = d0666dbf98cb4b41304b01e1b4f8ca15fe9288d8
 SHA512 (audiofile-0.3.6.tar.gz) = f9a1182d93e405c21eba79c5cc40962347bff13f1b3b732d9a396e3d1675297515188bd6eb43033aaa00e9bde74ff4628c1614462456529cabba464f03c1d5fa
 Size (audiofile-0.3.6.tar.gz) = 811733 bytes
 SHA1 (patch-libaudiofile_CAF.cpp) = ddea79105f9b1e7222f91649815668d3a8ee6e98
-SHA1 (patch-libaudiofile_modules_SimpleModule.h) = f1e3842d3d9ddcea6b547bbeb5991769855ab2fc
+SHA1 (patch-libaudiofile_modules_SimpleModule.h) = 356869de2119e868e84cc9d39f370270678a778c
diff -r 65b9ba475656 -r 5fba4f5be29e audio/libaudiofile/patches/patch-libaudiofile_modules_SimpleModule.h
--- a/audio/libaudiofile/patches/patch-libaudiofile_modules_SimpleModule.h      Sun Dec 18 23:40:22 2016 +0000
+++ b/audio/libaudiofile/patches/patch-libaudiofile_modules_SimpleModule.h      Mon Dec 19 00:14:43 2016 +0000
@@ -1,16 +1,41 @@
-$NetBSD: patch-libaudiofile_modules_SimpleModule.h,v 1.2 2016/12/18 23:40:23 maya Exp $
+$NetBSD: patch-libaudiofile_modules_SimpleModule.h,v 1.3 2016/12/19 00:14:43 maya Exp $
 
 Left shift of a negative number is UB and doesn't build (-fpermissive)
 Switch with functionally identical but well-defined operation.
+(same function used upstream)
+
+Just define it in the accessor rather than a cstatic global (which isn't
+actually cstatic, which is UB and optimized away at least by GCC)
 
 --- libaudiofile/modules/SimpleModule.h.orig   2013-03-06 05:30:03.000000000 +0000
 +++ libaudiofile/modules/SimpleModule.h
-@@ -123,7 +123,7 @@ struct signConverter
+@@ -122,17 +122,24 @@ struct signConverter
+       typedef typename IntTypes<Format>::SignedType SignedType;
        typedef typename IntTypes<Format>::UnsignedType UnsignedType;
  
-       static const int kScaleBits = (Format + 1) * CHAR_BIT - 1;
+-      static const int kScaleBits = (Format + 1) * CHAR_BIT - 1;
 -      static const int kMinSignedValue = -1 << kScaleBits;
-+      static const int kMinSignedValue = -(1 << kScaleBits);
- 
+-
        struct signedToUnsigned : public std::unary_function<SignedType, UnsignedType>
        {
+-              UnsignedType operator()(SignedType x) { return x - kMinSignedValue; }
++              UnsignedType operator()(SignedType x) {
++                      int kScaleBits = (Format + 1) * CHAR_BIT - 1;
++                      int kMaxSignedValue = (((1 << (kScaleBits - 1)) - 1) << 1) + 1;
++                      int kMinSignedValue = -kMaxSignedValue - 1;
++                      return x - kMinSignedValue;
++              }
+       };
+ 
+       struct unsignedToSigned : public std::unary_function<SignedType, UnsignedType>
+       {
+-              SignedType operator()(UnsignedType x) { return x + kMinSignedValue; }
++              SignedType operator()(UnsignedType x) {
++                      int kScaleBits = (Format + 1) * CHAR_BIT - 1;
++                      int kMaxSignedValue = (((1 << (kScaleBits - 1)) - 1) << 1) + 1;
++                      int kMinSignedValue = -kMaxSignedValue - 1;
++                      return x + kMinSignedValue;
++              }
+       };
+ };
+ 



Home | Main Index | Thread Index | Old Index