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
@@ -1,3 +1,8 @@
2016-08-29 Michael Pruett <michael@68k.org>

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

2016-07-05 Joerg Krause <joerg.krause@embedded.rocks>

* audiofile.pc.in:
Expand Down
3 changes: 2 additions & 1 deletion libaudiofile/modules/SimpleModule.h
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

2 comments on commit b62c902

@mschwendt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you like the fix from pull request #27?

@coypoop
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think in this case it's not cstatic which is another UB (I tried a similar fix and it was optimized away). perhaps just define it in the accessor?

Please sign in to comment.