Skip to content

Commit

Permalink
Fix undefined behavior in sign conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpruett committed Aug 30, 2016
1 parent 82f9131 commit b62c902
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2016-08-29 Michael Pruett <[email protected]>

* libaudiofile/modules/SimpleModule.h:
Fix undefined behavior in sign conversion.

2016-07-05 Joerg Krause <[email protected]>

* audiofile.pc.in:
Expand Down
3 changes: 2 additions & 1 deletion libaudiofile/modules/SimpleModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ struct signConverter
typedef typename IntTypes<Format>::UnsignedType UnsignedType;

static const int kScaleBits = (Format + 1) * CHAR_BIT - 1;
static const int kMinSignedValue = -1 << kScaleBits;
static const int kMaxSignedValue = (((1 << (kScaleBits - 1)) - 1) << 1) + 1;
static const int kMinSignedValue = -kMaxSignedValue - 1;

struct signedToUnsigned : public std::unary_function<SignedType, UnsignedType>
{
Expand Down

0 comments on commit b62c902

Please sign in to comment.