summaryrefslogtreecommitdiffstats
path: root/libblkid/src/encode.c
diff options
context:
space:
mode:
authorPali Rohár2017-05-16 23:51:50 +0200
committerPali Rohár2017-05-16 23:51:50 +0200
commit98bc12ab483858bbbd8b2c4b8de33e9679e957e3 (patch)
treefbe56fe9b789d5e790e1ddb654f374b084905547 /libblkid/src/encode.c
parentsu: remove duplicate const declaration (diff)
downloadkernel-qcow2-util-linux-98bc12ab483858bbbd8b2c4b8de33e9679e957e3.tar.gz
kernel-qcow2-util-linux-98bc12ab483858bbbd8b2c4b8de33e9679e957e3.tar.xz
kernel-qcow2-util-linux-98bc12ab483858bbbd8b2c4b8de33e9679e957e3.zip
libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8()
Diffstat (limited to 'libblkid/src/encode.c')
-rw-r--r--libblkid/src/encode.c17
1 files changed, 14 insertions, 3 deletions
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;