comparison src/lib-charset/charset-utf8.c @ 18144:7459c0891a85

lib-charset: UTF-8 -> UTF-8 translation was never returning CHARSET_RET_INCOMPLETE_INPUT Instead the incomplete input was just being modified into broken output.
author Timo Sirainen <tss@iki.fi>
date Sat, 10 Jan 2015 04:25:21 +0200
parents 3009a1a6f6d5
children 0e74934072e0
comparison
equal deleted inserted replaced
18143:55184e2a689f 18144:7459c0891a85
68 68
69 enum charset_result 69 enum charset_result
70 charset_to_utf8(struct charset_translation *t, 70 charset_to_utf8(struct charset_translation *t,
71 const unsigned char *src, size_t *src_size, buffer_t *dest) 71 const unsigned char *src, size_t *src_size, buffer_t *dest)
72 { 72 {
73 if (t->normalizer != NULL) { 73 return charset_utf8_to_utf8(t->normalizer, src, src_size, dest);
74 if (t->normalizer(src, *src_size, dest) < 0) 74 }
75
76 #endif
77
78 enum charset_result
79 charset_utf8_to_utf8(normalizer_func_t *normalizer,
80 const unsigned char *src, size_t *src_size, buffer_t *dest)
81 {
82 enum charset_result res = CHARSET_RET_OK;
83 size_t pos;
84
85 uni_utf8_partial_strlen_n(src, *src_size, &pos);
86 if (pos < *src_size) {
87 *src_size = pos;
88 res = CHARSET_RET_INCOMPLETE_INPUT;
89 }
90
91 if (normalizer != NULL) {
92 if (normalizer(src, *src_size, dest) < 0)
75 return CHARSET_RET_INVALID_INPUT; 93 return CHARSET_RET_INVALID_INPUT;
76 } else if (!uni_utf8_get_valid_data(src, *src_size, dest)) { 94 } else if (!uni_utf8_get_valid_data(src, *src_size, dest)) {
77 return CHARSET_RET_INVALID_INPUT; 95 return CHARSET_RET_INVALID_INPUT;
78 } else { 96 } else {
79 buffer_append(dest, src, *src_size); 97 buffer_append(dest, src, *src_size);
80 } 98 }
81 return CHARSET_RET_OK; 99 return res;
82 } 100 }
83
84 #endif