This takes care of null-terminating the buffer if it is too small, which wasn't handled properly before. Signed-off-by: Martin Storsjö <martin@martin.st>