Skip to content

Commit

Permalink
Merge pull request bitcoin#8 from luke-jr/avoid_ssize_t
Browse files Browse the repository at this point in the history
Avoid ssize_t
  • Loading branch information
luke-jr authored Jun 3, 2018
2 parents afa117a + 4aaeea0 commit 1c9930a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TESTS = \
tests/decode-zero.sh \
tests/encode.sh \
tests/encode-b58c.sh \
tests/encode-b58c-high.sh \
tests/encode-fail.sh \
tests/encode-neg-index.sh \
tests/encode-small.sh
Expand Down
7 changes: 5 additions & 2 deletions base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>

#include "libbase58.h"

Expand Down Expand Up @@ -147,7 +146,7 @@ bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)
{
const uint8_t *bin = data;
int carry;
ssize_t i, j, high, zcount = 0;
size_t i, j, high, zcount = 0;
size_t size;

while (zcount < binsz && !bin[zcount])
Expand All @@ -164,6 +163,10 @@ bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)
carry += 256 * buf[j];
buf[j] = carry % 58;
carry /= 58;
if (!j) {
// Otherwise j wraps to maxint which is > high
break;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/encode-b58c-high.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
b58=$(echo 'ff5a1fc5dd9e6f03819fca94a2d89669469667f9a0' | xxd -r -p | base58 -c)
test x$b58 = x2mkQLxaN3Y4CwN5E9rdMWNgsXX7VS6UnfeT

0 comments on commit 1c9930a

Please sign in to comment.