]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8()
authorPali Rohár <pali.rohar@gmail.com>
Tue, 16 May 2017 21:51:50 +0000 (23:51 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Tue, 16 May 2017 21:51:50 +0000 (23:51 +0200)
libblkid/src/blkidP.h
libblkid/src/encode.c

index de41473a870cdc5a246812e9ca0dabecf331f39d..4a148357a649c3017b693c0f1e52065f958f0456 100644 (file)
@@ -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 */
index b5b4363afff2f99b0d1f80ec0d0252fbfe39d7ed..33d349127e65fc582a39d007729acde08f718a93 100644 (file)
@@ -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;