diff --git a/ChangeLog b/ChangeLog index 15c6f542b..1de2cb20f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Check user, password, host, port parts for illegal characters. Thanks to bug report by Marco Manfredini * Source/GSMime.m: add convenience method for setting document type. + Fix error in recent change to base64 encoding. 2002-06-17 Richard Frith-Macdonald diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index dbf8ce2f9..ba46c726b 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -2887,15 +2887,14 @@ static NSCharacterSet *tokenSet = nil; for (sIndex = 0; sIndex < length; sIndex += 3) { - dBuf[dIndex] = b64[sBuf[sIndex] >> 2]; - dBuf[dIndex + 1] - = b64[((sBuf[sIndex] << 4) & 060) - | ((sBuf[sIndex + 1] >> 4) & 017)]; - dBuf[dIndex + 2] - = b64[((sBuf[sIndex + 1] << 2) & 074) - | ((sBuf[sIndex + 2] >> 6) & 03)]; - dBuf[dIndex + 3] = b64[sBuf[sIndex + 2] & 077]; - dIndex += 3; + int c0 = sBuf[sIndex]; + int c1 = sBuf[sIndex+1]; + int c2 = sBuf[sIndex+2]; + + dBuf[dIndex++] = b64[(c0 >> 2) & 077]; + dBuf[dIndex++] = b64[((c0 << 4) & 060) | ((c1 >> 4) & 017)]; + dBuf[dIndex++] = b64[((c1 << 2) & 074) | ((c2 >> 6) & 03)]; + dBuf[dIndex++] = b64[c2 & 077]; } /* If len was not a multiple of 3, then we have encoded too