Some clients may tolerate that, but for example PAPI only strips from right, while garbage can be anything.
There are two main sources why garbage hapens. First, the target buffer comes from alloc and is not memset to zero. Second, strncpy is used for copying names, which ends at zero byte.
As table of variable length strings is tricky to achieve, the only fix is to use memcpy (or memset).