Part of bug #1523610: fix miscalculation of buffer length.

Also add a guard against NULL in converttuple and add a test case
(that previously would have crashed).
3 files changed