unconditionalcoder unconditionalcoder - 2 months ago 19
C Question

Base 64 decode returning NULL in C

I have a base 64 encoded string that I want to decode.
It looks like this:


when I do..

gsize *out_len;
unsigned const char *decoded;
decoded = g_base_64_decode(myString, out_len);

and print out my decoded string, I get NULL also, i get the assertion:
'out_len != NULL' failed from Glib

Why is this happening? How can I decode my string properly with this function? https://developer.gnome.org/glib/stable/glib-Base64-Encoding.html#g-base64-decode-step


The out_len parameter is an output parameter. This means that you typically create an out_len variable of type gsize on the stack like this:

gsize out_len;

and then you call the function passing a pointer to the aforementioned variable (i.e. you pass the address of it: &out_len), e.g.:

decoded = g_base_64_decode(myString, &out_len);