conf: Properly truncate wide character names in virDomainObjGetShortName
conf: Properly truncate wide character names in virDomainObjGetShortName

We always truncated the name at 20 bytes instead of characters.  In
case 20 bytes were in the middle of a multi-byte character, then the
string became invalid and various parts of the code would error
out (e.g. XML parsing of that string).  Let's instead properly
truncate it after 20 characters instead.

We cannot test this in our test suite because we would need to know
what locales are installed on the system where the tests are ran and
if there is supported one (most probably there will be, but we cannot
be 100% sure), we could initialize gettext in qemuxml2argvtest, but
there would still be a chance of getting two different (both valid,
though) results.

In order to test this it is enough to start a machine with a name for
which trimming it after 20 bytes would create invalid sequence (e.g.
1234567890123456789č where č is any multi-byte character).  Then start
the domain and restart libvirtd.  The domain would disappear because
such illegal sequence will not go through the XML parser.  And that's
not a bug of the parser, it should not be in the XML in the first
place, but since we don't use any sophisticated formatter, just
mash some strings together, the formatting succeeds.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1448766

Signed-off-by: Martin Kletzander <e82f23e74d43760279ebcc505dac4ae70d5627d0@redhat.com>

eskultety/libvirt,fabianfreyer/libvirt,eskultety/libvirt,libvirt/libvirt,fabianfreyer/libvirt,libvirt/libvirt,jfehlig/libvirt,zippy2/libvirt,nertpinx/libvirt,zippy2/libvirt,crobinso/libvirt,jfehlig/libvirt,jfehlig/libvirt,zippy2/libvirt,fabianfreyer/libvirt,eskultety/libvirt,jardasgit/libvirt,crobinso/libvirt,jardasgit/libvirt,fabianfreyer/libvirt,olafhering/libvirt,andreabolognani/libvirt,jardasgit/libvirt,eskultety/libvirt,olafhering/libvirt,fabianfreyer/libvirt,libvirt/libvirt,andreabolognani/libvirt,olafhering/libvirt,nertpinx/libvirt,nertpinx/libvirt,jardasgit/libvirt,nertpinx/libvirt,andreabolognani/libvirt,olafhering/libvirt,andreabolognani/libvirt,nertpinx/libvirt,crobinso/libvirt,crobinso/libvirt,jardasgit/libvirt,libvirt/libvirt,eskultety/libvirt,jfehlig/libvirt,andreabolognani/libvirt,zippy2/libvirt