Commit | Line | Data |
---|---|---|
a8e14943 HG |
1 | Based on (hunk for changelog removed) |
2 | From b62c902dd258125cac86cd2df21fc898035a43d3 Mon Sep 17 00:00:00 2001 | |
3 | From: Michael Pruett <michael@68k.org> | |
4 | Date: Mon, 29 Aug 2016 23:08:26 -0500 | |
5 | Subject: [PATCH] Fix undefined behavior in sign conversion. | |
6 | ||
7 | ||
8 | --- | |
9 | ChangeLog | 5 +++++ | |
10 | libaudiofile/modules/SimpleModule.h | 3 ++- | |
11 | 2 files changed, 7 insertions(+), 1 deletion(-) | |
12 | ||
13 | diff --git a/libaudiofile/modules/SimpleModule.h b/libaudiofile/modules/SimpleModule.h | |
14 | index 03c6c69..bad85ad 100644 | |
15 | --- a/libaudiofile/modules/SimpleModule.h | |
16 | +++ b/libaudiofile/modules/SimpleModule.h | |
17 | @@ -123,7 +123,8 @@ struct signConverter | |
18 | typedef typename IntTypes<Format>::UnsignedType UnsignedType; | |
19 | ||
20 | static const int kScaleBits = (Format + 1) * CHAR_BIT - 1; | |
21 | - static const int kMinSignedValue = -1 << kScaleBits; | |
22 | + static const int kMaxSignedValue = (((1 << (kScaleBits - 1)) - 1) << 1) + 1; | |
23 | + static const int kMinSignedValue = -kMaxSignedValue - 1; | |
24 | ||
25 | struct signedToUnsigned : public std::unary_function<SignedType, UnsignedType> | |
26 | { |