Fix malloc

1. sizeof(char) is always 1 according to c99 so they are removed.
2. we need to +1 for a terminator.
3. len_in and len_out are size_t.
4. replace 2 as ((length % 3) ? (3 - (length % 3)) : 0) to be more exact. (just for fun)