Skip to content

Instantly share code, notes, and snippets.

@dploeger
Created March 13, 2017 08:27
Show Gist options
  • Save dploeger/efb7890a65583168505df03564b1b312 to your computer and use it in GitHub Desktop.
Save dploeger/efb7890a65583168505df03564b1b312 to your computer and use it in GitHub Desktop.
nibtools bitshifter.c patch for macOS
Index: bitshifter.c
===================================================================
--- bitshifter.c (revision 637)
+++ bitshifter.c (working copy)
@@ -439,13 +439,25 @@
// > 0 <= C <= 7 (see above)
// > *b = Next bit position to be copied from 'db' (1 <= B <= 8)
// > [ ((Q << C) & 0xff00) + new bits from db ] >> C
- **q = ( ( (__int32)((**q) >> (8-*c)) << 8) | (((__int32)db << (*b-1)) & 0xff) ) >> *c;
+ **q = ( ( (int32_t)((**q) >> (8-*c)) << 8) | (((int32_t)db << (*b-1)) & 0xff) ) >> *c;
+
// Determine number 'd' of copied bits (lowest value of following):
// - At most (8-*c) free bits in Q were filled
// - At most (9-*b) bits could be copied from db
// - At most NumDataBits were left to be copied
- d = min(min(8-*c, 9-*b), NumDataBits);
+ BYTE mina;
+ if (8-*c < 9-*b) {
+ mina = 8-*c;
+ } else {
+ mina = 9-*c;
+ }
+
+ if (mina < NumDataBits) {
+ d = mina;
+ } else {
+ d = NumDataBits;
+ }
// Now: 1 <= d <= 8
// Update source position P.B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment