Title: [C++] Encoding: XSCryptCryptoBase64::encode()

Berin,

I've found very interesting problem with encoding. Take a look at this line of the code from XSCryptCryptoBase64::encode():

t = ((m_inputBuffer[i++] << 4) & 0x30) | (m_inputBuffer[i] >> 4);

The problem is that order of execution (left to right or right to left) is not defined for "|" operator in C++ language and is left to compiler to decide. There are cases where first is being executed left side of operator "|" and there are cases where first is executed right side and then left side. Because of operator ++ in _expression_ i++, results are different and encoding fails. I've noticed this behaviour (right to left order) using Multithreaded (/MT) runtime, but when I use Multitreaded DLL (/MD) runtime order is left to right (using VC7.1 compiler). The best way to avoid this is to break this line into (at least) two lines and avoid ++ operator side effect.

Best regards,
Milan

Reply via email to