Avoid pointless string alloc call, add checks for dynamic memory
and swap calls from switch_mprintf to asprintf, note that this
somewhat changes behaviour (no %q in printf).