diff src/lib-imap/imap-quote.c @ 898:0d5be52d7131 HEAD

Use unsigned char* when accessing non-NUL terminating strings. Compiler warnings would then notify about accidentally passing them to functions which require them NUL-terminated. Changed a few functions to use void* to avoid unneeded casting.
author Timo Sirainen <tss@iki.fi>
date Sat, 04 Jan 2003 19:26:29 +0200
parents 41ec8cadd238
children fd8888f6f037
line wrap: on
line diff
--- a/src/lib-imap/imap-quote.c	Sat Jan 04 15:22:29 2003 +0200
+++ b/src/lib-imap/imap-quote.c	Sat Jan 04 19:26:29 2003 +0200
@@ -13,7 +13,7 @@
 #define IS_BREAK_OR_CRLF_CHAR(c) \
 	(IS_BREAK_CHAR(c) || (c) == '\r' || (c) == '\n')
 
-static size_t next_token_quoted(const char *value, size_t len,
+static size_t next_token_quoted(const unsigned char *value, size_t len,
 				int *need_qp, int *quoted)
 {
 	size_t i;
@@ -22,7 +22,7 @@
 	*quoted = TRUE;
 
 	for (i = *quoted ? 0 : 1; i < len; i++) {
-		if ((unsigned char)value[i] & 0x80)
+		if (value[i] & 0x80)
 			*need_qp = TRUE;
 
 		if (value[i] == '"' || value[i] == '\r' || value[i] == '\n') {
@@ -35,7 +35,7 @@
 	return i;
 }
 
-static size_t next_token(const char *value, size_t len,
+static size_t next_token(const unsigned char *value, size_t len,
 			 int *need_qp, int *quoted, int qp_on)
 {
 	size_t i = 0;
@@ -68,7 +68,7 @@
 
 	/* then stop at break-char */
 	for (; i < len; i++) {
-		if ((unsigned char)value[i] & 0x80)
+		if (value[i] & 0x80)
 			*need_qp = TRUE;
 
 		if (IS_BREAK_OR_CRLF_CHAR(value[i]))
@@ -78,7 +78,8 @@
 	return i;
 }
 
-static void append_quoted_qp(String *str, const char *value, size_t len)
+static void append_quoted_qp(String *str, const unsigned char *value,
+			     size_t len)
 {
 	size_t i;
 	unsigned char c;
@@ -96,15 +97,15 @@
 			str_append_c(str, value[i]);
 		} else {
 			str_append_c(str, '=');
-			c = (unsigned char)value[i] >> 4;
+			c = value[i] >> 4;
 			str_append_c(str, c < 10 ? (c+'0') : (c-10+'A'));
-			c = (unsigned char)value[i] & 0x0f;
+			c = value[i] & 0x0f;
 			str_append_c(str, c < 10 ? (c+'0') : (c-10+'A'));
 		}
 	}
 }
 
-static void append_quoted(String *str, const char *value, size_t len)
+static void append_quoted(String *str, const unsigned char *value, size_t len)
 {
 	size_t i;
 
@@ -116,7 +117,7 @@
 }
 
 /* does two things: 1) escape '\' and '"' characters, 2) 8bit text -> QP */
-static String *get_quoted_str(const char *value, size_t value_len)
+static String *get_quoted_str(const unsigned char *value, size_t value_len)
 {
 	String *str;
 	size_t token_len;
@@ -165,13 +166,14 @@
 const char *imap_quote_str_nil(const char *value)
 {
 	return value == NULL ? "NIL" :
-		str_c(get_quoted_str(value, strlen(value)));
+		str_c(get_quoted_str((const unsigned char *) value,
+				     strlen(value)));
 }
 
-char *imap_quote_value(Pool pool, const char *value, size_t value_len)
+char *imap_quote_value(Pool pool, const unsigned char *value, size_t value_len)
 {
 	String *str;
 
 	str = get_quoted_str(value, value_len);
-	return p_strndup(pool, str_c(str), str_len(str));
+	return p_strndup(pool, str_data(str), str_len(str));
 }