Add NULL checks to the base64 functions that take pointers. (#399611,

2007-03-06  Matthias Clasen  <mclasen@redhat.com>

        * glib/gbase64.c: Add NULL checks to the base64
        functions that take pointers.  (#399611, Martyn Russell)


svn path=/trunk/; revision=5371
This commit is contained in:
Matthias Clasen 2007-03-06 05:36:57 +00:00 committed by Matthias Clasen
parent 04b0520e09
commit 5ae803a47f
2 changed files with 34 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2007-03-06 Matthias Clasen <mclasen@redhat.com>
* glib/gbase64.c: Add NULL checks to the base64
functions that take pointers. (#399611, Martyn Russell)
2007-03-06 Matthias Clasen <mclasen@redhat.com>
Work with Solaris gettext (#341988, Laszlo Peter)

View File

@ -38,8 +38,8 @@ static const char base64_alphabet[] =
/**
* g_base64_encode_step:
* @in: the binary data to encode.
* @len: the length of @in.
* @in: the binary data to encode
* @len: the length of @in
* @break_lines: whether to break long lines
* @out: pointer to destination buffer
* @state: Saved state between steps, initialize to 0
@ -76,6 +76,11 @@ g_base64_encode_step (const guchar *in,
char *outptr;
const guchar *inptr;
g_return_val_if_fail (in != NULL, 0);
g_return_val_if_fail (out != NULL, 0);
g_return_val_if_fail (state != NULL, 0);
g_return_val_if_fail (save != NULL, 0);
if (len <= 0)
return 0;
@ -172,6 +177,10 @@ g_base64_encode_close (gboolean break_lines,
int c1, c2;
char *outptr = out;
g_return_val_if_fail (out != NULL, 0);
g_return_val_if_fail (state != NULL, 0);
g_return_val_if_fail (save != NULL, 0);
c1 = ((unsigned char *) save) [1];
c2 = ((unsigned char *) save) [2];
@ -201,8 +210,8 @@ g_base64_encode_close (gboolean break_lines,
/**
* g_base64_encode:
* @data: the binary data to encode.
* @len: the length of @data.
* @data: the binary data to encode
* @len: the length of @data
*
* Encode a sequence of binary data into its Base-64 stringified
* representation.
@ -220,6 +229,9 @@ g_base64_encode (const guchar *data,
gint state = 0, outlen;
gint save = 0;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (len > 1, 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);
@ -284,6 +296,14 @@ g_base64_decode_step (const gchar *in,
guchar last[2];
unsigned int v;
int i;
g_return_val_if_fail (in != NULL, 0);
g_return_val_if_fail (out != NULL, 0);
g_return_val_if_fail (state != NULL, 0);
g_return_val_if_fail (save != NULL, 0);
if (len <= 0)
return 0;
inend = (const guchar *)in+len;
outptr = out;
@ -323,8 +343,8 @@ g_base64_decode_step (const gchar *in,
/**
* g_base64_decode:
* @text: zero-terminated string with base64 text to decode.
* @out_len: The length of the decoded data is written here.
* @text: zero-terminated string with base64 text to decode
* @out_len: The length of the decoded data is written here
*
* Decode a sequence of Base-64 encoded text into binary data
*
@ -341,6 +361,9 @@ g_base64_decode (const gchar *text,
gint inlen, state = 0;
guint save = 0;
g_return_val_if_fail (text != NULL, NULL);
g_return_val_if_fail (out_len != NULL, NULL);
inlen = strlen (text);
ret = g_malloc0 (inlen * 3 / 4);