Don't refuse to encode a single byte. (Milan Crha)

2007-11-23  Matthias Clasen  <mclasen@redhat.com>

        * glib/gbase64.c (g_base64_encode): Don't refuse to encode
        a single byte.  (Milan Crha)

        * tests/base64-test.c: Test encoding short strings.



svn path=/trunk/; revision=5919
This commit is contained in:
Matthias Clasen
2007-11-23 17:58:00 +00:00
committed by Matthias Clasen
parent 39ad6fbd02
commit 78c06eafe1
3 changed files with 23 additions and 11 deletions

View File

@@ -231,16 +231,14 @@ g_base64_encode (const guchar *data,
gint save = 0;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (len > 1, NULL);
g_return_val_if_fail (len > 0, NULL);
/* We can use a smaller limit here, since we know the saved state is 0 */
out = g_malloc (len * 4 / 3 + 4);
outlen = g_base64_encode_step (data, len, FALSE, out, &state, &save);
outlen += g_base64_encode_close (FALSE,
out + outlen,
&state,
&save);
outlen += g_base64_encode_close (FALSE, out + outlen, &state, &save);
out[outlen] = '\0';
return (gchar *) out;
}