summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2009-10-15 16:13:53 -0400
committerMathias Stearn <mathias@10gen.com>2009-10-15 16:14:20 -0400
commit0abfa82d540ae6e7fc25b58d30af37340b2f7ba8 (patch)
tree42a32899af15acb9a1ce8b4c3f97c15ec3731782
parent7636df40d7910bcce2a138f6ec09398c1d9f3339 (diff)
downloadmongo-0abfa82d540ae6e7fc25b58d30af37340b2f7ba8.tar.gz
GCC4.4 doesn't like char array subscripts
-rw-r--r--util/base64.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/util/base64.cpp b/util/base64.cpp
index 18281c5c4e9..44d335611bf 100644
--- a/util/base64.cpp
+++ b/util/base64.cpp
@@ -25,13 +25,13 @@ namespace mongo {
class Alphabet {
public:
Alphabet(){
- encode =
+ encode = (unsigned char*)
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"+/";
- decode = (char*)malloc(257);
+ decode = (unsigned char*)malloc(257);
memset( decode , 0 , 256 );
for ( int i=0; i<64; i++ ){
decode[ encode[i] ] = i;
@@ -44,7 +44,7 @@ namespace mongo {
}
void test(){
- assert( strlen( encode ) == 64 );
+ assert( strlen( (char*)encode ) == 64 );
for ( int i=0; i<26; i++ )
assert( encode[i] == toupper( encode[i+26] ) );
}
@@ -54,22 +54,22 @@ namespace mongo {
}
private:
- const char * encode;
+ const unsigned char * encode;
public:
- char * decode;
+ unsigned char * decode;
} alphabet;
void encode( stringstream& ss , const char * data , int size ){
for ( int i=0; i<size; i+=3 ){
int left = size - i;
- const char * start = data + i;
+ const unsigned char * start = (const unsigned char*)data + i;
// byte 0
ss << alphabet.e(start[0]>>2);
// byte 1
- char temp = ( start[0] << 4 );
+ unsigned char temp = ( start[0] << 4 );
if ( left == 1 ){
ss << alphabet.e(temp);
break;
@@ -113,12 +113,12 @@ namespace mongo {
void decode( stringstream& ss , const string& s ){
uassert( "invalid base64" , s.size() % 4 == 0 );
- const char * data = s.c_str();
+ const unsigned char * data = (const unsigned char*)s.c_str();
int size = s.size();
- char buf[3];
+ unsigned char buf[3];
for ( int i=0; i<size; i+=4){
- const char * start = data + i;
+ const unsigned char * start = data + i;
buf[0] = ( ( alphabet.decode[start[0]] << 2 ) & 0xFC ) | ( ( alphabet.decode[start[1]] >> 4 ) & 0x3 );
buf[1] = ( ( alphabet.decode[start[1]] << 4 ) & 0xF0 ) | ( ( alphabet.decode[start[2]] >> 2 ) & 0xF );
buf[2] = ( ( alphabet.decode[start[2]] << 6 ) & 0xC0 ) | ( ( alphabet.decode[start[3]] & 0x3F ) );
@@ -130,7 +130,7 @@ namespace mongo {
len = 1;
}
}
- ss.write( buf , len );
+ ss.write( (const char*)buf , len );
}
}