From: Pali Rohár Date: Tue, 16 May 2017 21:51:50 +0000 (+0200) Subject: libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8() X-Git-Tag: v2.30-rc2~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98bc12ab483858bbbd8b2c4b8de33e9679e957e3;p=thirdparty%2Futil-linux.git libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8() --- diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h index de41473a87..4a148357a6 100644 --- a/libblkid/src/blkidP.h +++ b/libblkid/src/blkidP.h @@ -543,5 +543,6 @@ extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len, #define BLKID_ENC_UTF16BE 0 #define BLKID_ENC_UTF16LE 1 +#define BLKID_ENC_LATIN1 2 #endif /* _BLKID_BLKIDP_H */ diff --git a/libblkid/src/encode.c b/libblkid/src/encode.c index b5b4363aff..33d349127e 100644 --- a/libblkid/src/encode.c +++ b/libblkid/src/encode.c @@ -239,11 +239,22 @@ size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len, size_t i, j; uint16_t c; - for (j = i = 0; i + 2 <= count; i += 2) { - if (enc == BLKID_ENC_UTF16LE) + for (j = i = 0; i < count; i++) { + if (enc == BLKID_ENC_UTF16LE) { + if (i+2 > count) + break; c = (src[i+1] << 8) | src[i]; - else /* BLKID_ENC_UTF16BE */ + i++; + } else if (enc == BLKID_ENC_UTF16BE) { + if (i+2 > count) + break; c = (src[i] << 8) | src[i+1]; + i++; + } else if (enc == BLKID_ENC_LATIN1) { + c = src[i]; + } else { + return 0; + } if (c == 0) { dest[j] = '\0'; break;