dovecot-2.2: uni_utf8_to_decomposed_titlecase(): Require input l...

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 15 03:12:36 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/d5ebec837bfd
changeset: 15052:d5ebec837bfd
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 15 03:09:57 2012 +0300
description:
uni_utf8_to_decomposed_titlecase(): Require input length to be exact now.
Most of the callers did that already anyway

diffstat:

 src/lib-storage/index/index-sort.c |   2 +-
 src/lib/unichar.c                  |  10 +++++-----
 src/lib/unichar.h                  |   2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diffs (58 lines):

diff -r 9ad9a79c1747 -r d5ebec837bfd src/lib-storage/index/index-sort.c
--- a/src/lib-storage/index/index-sort.c	Fri Sep 14 23:11:27 2012 +0300
+++ b/src/lib-storage/index/index-sort.c	Sat Sep 15 03:09:57 2012 +0300
@@ -443,7 +443,7 @@
 		i_unreached();
 	}
 
-	(void)uni_utf8_to_decomposed_titlecase(str, (size_t)-1, dest);
+	(void)uni_utf8_to_decomposed_titlecase(str, strlen(str), dest);
 	return ret;
 }
 
diff -r 9ad9a79c1747 -r d5ebec837bfd src/lib/unichar.c
--- a/src/lib/unichar.c	Fri Sep 14 23:11:27 2012 +0300
+++ b/src/lib/unichar.c	Sat Sep 15 03:09:57 2012 +0300
@@ -307,7 +307,7 @@
 	buffer_append(output, utf8_replacement_char, UTF8_REPLACEMENT_CHAR_LEN);
 }
 
-int uni_utf8_to_decomposed_titlecase(const void *_input, size_t max_len,
+int uni_utf8_to_decomposed_titlecase(const void *_input, size_t size,
 				     buffer_t *output)
 {
 	const unsigned char *input = _input;
@@ -315,17 +315,17 @@
 	unichar_t chr;
 	int ret = 0;
 
-	while (max_len > 0 && *input != '\0') {
-		if (uni_utf8_get_char_n(input, max_len, &chr) <= 0) {
+	while (size > 0) {
+		if (uni_utf8_get_char_n(input, size, &chr) <= 0) {
 			/* invalid input. try the next byte. */
 			ret = -1;
-			input++; max_len--;
+			input++; size--;
 			output_add_replacement_char(output);
 			continue;
 		}
 		bytes = uni_utf8_char_bytes(*input);
 		input += bytes;
-		max_len -= bytes;
+		size -= bytes;
 
 		chr = uni_ucs4_to_titlecase(chr);
 		if (chr >= HANGUL_FIRST && chr <= HANGUL_LAST)
diff -r 9ad9a79c1747 -r d5ebec837bfd src/lib/unichar.h
--- a/src/lib/unichar.h	Fri Sep 14 23:11:27 2012 +0300
+++ b/src/lib/unichar.h	Sat Sep 15 03:09:57 2012 +0300
@@ -69,7 +69,7 @@
    output buffer. Returns 0 if ok, -1 if input was invalid. This generates
    output that's compatible with i;unicode-casemap comparator. Invalid input
    is replaced with unicode replacement character (0xfffd). */
-int uni_utf8_to_decomposed_titlecase(const void *input, size_t max_len,
+int uni_utf8_to_decomposed_titlecase(const void *input, size_t size,
 				     buffer_t *output);
 
 /* If input contains only valid UTF-8 characters, return TRUE without updating


More information about the dovecot-cvs mailing list