]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/base64.cpp
remove "item.cchTextMax=0" line from SetItem() as it doesn't seem to make any sense...
[wxWidgets.git] / src / common / base64.cpp
index 89025b0b56f94e568a6ac323023507c19f738166..54b0cc752f424611ba1e4d8c01b346d93d42f7a9 100644 (file)
@@ -18,7 +18,7 @@ wxBase64Encode(char *dst, size_t dstLen, const void *src_, size_t srcLen)
 {
     wxCHECK_MSG( src_, wxCONV_FAILED, _T("NULL input buffer") );
 
-    const unsigned char *src = wx_static_cast(const unsigned char *, src_);
+    const unsigned char *src = static_cast<const unsigned char *>(src_);
 
     static const char b64[] =
         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -71,7 +71,7 @@ wxBase64Decode(void *dst_, size_t dstLen,
 {
     wxCHECK_MSG( src, wxCONV_FAILED, _T("NULL input buffer") );
 
-    unsigned char *dst = wx_static_cast(unsigned char *, dst_);
+    unsigned char *dst = static_cast<unsigned char *>(dst_);
 
     size_t decLen = 0;
 
@@ -88,7 +88,7 @@ wxBase64Decode(void *dst_, size_t dstLen,
         PAD
     };
 
-    static const char decode[256] =
+    static const unsigned char decode[256] =
     {
         WSP,INV,INV,INV,INV,INV,INV,INV,INV,WSP,WSP,INV,WSP,WSP,INV,INV,
         INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,INV,
@@ -118,7 +118,7 @@ wxBase64Decode(void *dst_, size_t dstLen,
     const char *p;
     for ( p = src; srcLen; p++, srcLen-- )
     {
-        const char c = decode[(int)*p];     // cast just to suppress warnings
+        const unsigned char c = decode[static_cast<unsigned char>(*p)];
         switch ( c )
         {
             case WSP:
@@ -132,7 +132,7 @@ wxBase64Decode(void *dst_, size_t dstLen,
 
                 // force the loop to stop and an error to be returned
                 n = -1;
-                srcLen = 0;
+                srcLen = 1;
                 break;
 
             case PAD:
@@ -156,7 +156,7 @@ wxBase64Decode(void *dst_, size_t dstLen,
                 {
                     // force the loop terminate with an error
                     n = -1;
-                    srcLen = 0;
+                    srcLen = 1;
                 }
                 break;
 
@@ -165,7 +165,7 @@ wxBase64Decode(void *dst_, size_t dstLen,
                 {
                     // nothing is allowed after the end so provoke error return
                     n = -1;
-                    srcLen = 0;
+                    srcLen = 1;
                     break;
                 }
 
@@ -194,7 +194,11 @@ wxBase64Decode(void *dst_, size_t dstLen,
     if ( n )
     {
         if ( posErr )
-            *posErr = p - src;
+        {
+            // notice that the error was on a previous position as we did one
+            // extra "p++" in the loop line after it
+            *posErr = p - src - 1;
+        }
 
         return wxCONV_FAILED;
     }