summaryrefslogtreecommitdiff
path: root/utils/b64tools.cc
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
commit6f29f345dc06c1a1033475eac1d1340781d1d603 (patch)
tree6fa4cdd7aefd7d54c9585c2c6274db61bb8b159a /utils/b64tools.cc
parentb510da2e562c695c90d565eb295c749569c59be8 (diff)
parentc615c37501fa8576584a510a9d2bfe2fdd5bace7 (diff)
merge upstream/master
Diffstat (limited to 'utils/b64tools.cc')
-rw-r--r--utils/b64tools.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/utils/b64tools.cc b/utils/b64tools.cc
index 5512f975..78c1cb4e 100644
--- a/utils/b64tools.cc
+++ b/utils/b64tools.cc
@@ -10,9 +10,10 @@ static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$
static void encodeblock(const unsigned char* in, ostream* os, int len) {
char out[4];
+ // cerr << len << endl;
out[0] = cb64[ in[0] >> 2 ];
- out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
- out[2] = (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
+ out[1] = cb64[ ((in[0] & 0x03) << 4) | (len > 1 ? ((in[1] & 0xf0) >> 4) : static_cast<unsigned char>(0))];
+ out[2] = (len > 2 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
out[3] = (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
os->write(out, 4);
}