diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-04-07 14:03:25 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-07 14:03:25 -0400 |
commit | f1613b53c57af05250b71f31eda037bf82f1e725 (patch) | |
tree | 18bd9a9e55f1242a7768f428732a7029a79a4d1b /src/common | |
parent | a5b50ef25b94e5220655a72417736d09dbd4a3c5 (diff) | |
parent | 4812441d3465f4f2fc6763ee644f79d5a9c8661b (diff) | |
download | tor-f1613b53c57af05250b71f31eda037bf82f1e725.tar.gz tor-f1613b53c57af05250b71f31eda037bf82f1e725.zip |
Merge remote-tracking branch 'public/bug21894_029' into maint-0.3.0
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util_format.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/common/util_format.c b/src/common/util_format.c index 6e0a04586a..7e8ee1b868 100644 --- a/src/common/util_format.c +++ b/src/common/util_format.c @@ -51,9 +51,10 @@ base32_encode(char *dest, size_t destlen, const char *src, size_t srclen) for (i=0,bit=0; bit < nbits; ++i, bit+=5) { /* set v to the 16-bit value starting at src[bits/8], 0-padded. */ - v = ((uint8_t)src[bit/8]) << 8; - if (bit+5<nbits) - v += (uint8_t)src[(bit/8)+1]; + size_t idx = bit / 8; + v = ((uint8_t)src[idx]) << 8; + if (idx+1 < srclen) + v += (uint8_t)src[idx+1]; /* set u to the 5-bit value at the bit'th bit of buf. */ u = (v >> (11-(bit%8))) & 0x1F; dest[i] = BASE32_CHARS[u]; |