Jump to content

Talk:Algorithm Implementation/Miscellaneous/Base64

Page contents not supported in other languages.
Add topic
From Wikibooks, open books for an open world

Fixed buffer overflow problem in encoder C source code

[edit source]

Before this source code was moved to Wikibooks, I noticed there was a buffer overflow bug in the C version of the base64 encoder that could cause memory corruption 1 byte past the stated end of the caller's result buffer. See: http://en.wikipedia.org/wiki/Talk:Base64#Apparent_buffer_overflow_bug_in_C_code I have fixed this bug here. I also made the function return int instead of void, so that the caller can tell whether the encoder was passed a buffer sufficiently large to receive the complete encoding. The function now returns 1 if successful, or 0 if the encoding is not complete. CosineKitty (talk) 18:45, 26 May 2008 (UTC)Reply

Fixed another buffer overflow: On certain compilers (e.g. Arduino, -Os), the line e.g.

 n = data[x] << 16; 

is compiled as n = (uint32_t)(data[x] << 16); so n is set to 0. fixed it to:

 n = ((uint32_t)data[x]) << 16; 

--Ntg sf (discusscontribs) 17:47, 7 October 2014 (UTC)Reply

While the cast is needed, the outer parenthesis are not, unless I'm mistaken. So it should be n = (uint32_t)data[x] << 16;. --Stw (discusscontribs) 16:43, 16 January 2016 (UTC)Reply

Added C++ encoder and decoder example

[edit source]

Er.. yup. I added it :P Billyoneal (talk) 01:48, 7 May 2009 (UTC)Reply


Group by language instead of encoding and decoding?

[edit source]

I noticed that in the Java decoding section that both the encoding and decoding is done here.

Should the code be separated or should it be grouped by language instead of encode/decode? Lone wolfII (talk) 08:14, 19 September 2009 (UTC)Reply