api: fix function string_decode_base64

The result of function was sometimes wrong, for example base64 decoding of
"YWJj" was returning "ab" instead of "abc".
v2.8-utf8proc
Sébastien Helleu 2014-08-02 16:43:25 +02:00
parent ad07527007
commit 8a93906beb
2 changed files with 16 additions and 21 deletions

View File

@ -100,6 +100,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
* core: display a warning in case of inconsistency between the options
weechat.look.save_{config|layout}_on_exit
* tests: add unit tests using CppUTest
* api: fix function string_decode_base64
* api: fix function string_format_size on 32-bit systems
* api: add argument "flags" in function hdata_new_list
* api: change type of arguments displayed/highlight in hook_print callback from

View File

@ -2477,7 +2477,7 @@ string_convbase64_6x4_to_8x3 (const unsigned char *from, unsigned char *to)
{
to[0] = from[0] << 2 | from[1] >> 4;
to[1] = from[1] << 4 | from[2] >> 2;
to[2] = ((from[2] << 6) & 0xc0) | from[3];
to[2] = from[2] << 6 | from[3];
}
/*
@ -2508,34 +2508,28 @@ string_decode_base64 (const char *from, char *to)
while (ptr_from && ptr_from[0])
{
length = 0;
in[0] = 0;
in[1] = 0;
in[2] = 0;
in[3] = 0;
for (i = 0; i < 4; i++)
{
in[i] = 0;
}
for (i = 0; i < 4; i++)
{
c = 0;
while (ptr_from[0] && (c == 0))
{
c = (unsigned char) ptr_from[0];
ptr_from++;
c = ((c < 43) || (c > 122)) ? 0 : base64_table[c - 43];
if (c)
c = (c == '$') ? 0 : c - 61;
}
if (ptr_from[0])
if (!ptr_from[0])
break;
c = (unsigned char) ptr_from[0];
ptr_from++;
c = ((c < 43) || (c > 122)) ? 0 : base64_table[c - 43];
if (c)
c = (c == '$') ? 0 : c - 61;
if (c)
{
length++;
if (c)
in[i] = c - 1;
in[i] = c - 1;
}
else
{
in[i] = '\0';
break;
}
}
if (length)
if (length > 0)
{
string_convbase64_6x4_to_8x3 (in, out);
for (i = 0; i < length - 1; i++)