From 98bc12ab483858bbbd8b2c4b8de33e9679e957e3 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Tue, 16 May 2017 23:51:50 +0200 Subject: libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8() --- libblkid/src/blkidP.h | 1 + libblkid/src/encode.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'libblkid') diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h index de41473a8..4a148357a 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 b5b4363af..33d349127 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; -- cgit v1.2.3-55-g7522