diff -uNrp zabbix-2.0.10.bk/include/db.h zabbix-2.0.10/include/db.h
--- zabbix-2.0.10.bk/include/db.h	2013-12-09 18:21:41.000000000 +0900
+++ zabbix-2.0.10/include/db.h	2013-12-13 08:48:59.208101696 +0900
@@ -87,61 +87,62 @@ zbx_graph_item_type;
 #define ZBX_DB_CONNECT_EXIT	1
 #define ZBX_DB_CONNECT_ONCE	2
 
+#define utf8_buf_size(a)	((a) * 4 + 1)
 #define TRIGGER_DESCRIPTION_LEN		255
 #define TRIGGER_EXPRESSION_LEN		255
-#define TRIGGER_EXPRESSION_LEN_MAX	TRIGGER_EXPRESSION_LEN+1
+#define TRIGGER_EXPRESSION_LEN_MAX	utf8_buf_size(TRIGGER_EXPRESSION_LEN)
 #define TRIGGER_ERROR_LEN		128
-#define TRIGGER_ERROR_LEN_MAX		TRIGGER_ERROR_LEN+1
+#define TRIGGER_ERROR_LEN_MAX		utf8_buf_size(TRIGGER_ERROR_LEN)
 
 #define HOST_HOST_LEN			MAX_ZBX_HOSTNAME_LEN
-#define HOST_HOST_LEN_MAX		HOST_HOST_LEN+1
+#define HOST_HOST_LEN_MAX		utf8_buf_size(HOST_HOST_LEN)
 #define HOST_ERROR_LEN			128
-#define HOST_ERROR_LEN_MAX		HOST_ERROR_LEN+1
+#define HOST_ERROR_LEN_MAX		utf8_buf_size(HOST_ERROR_LEN)
 #define HOST_IPMI_USERNAME_LEN		16
-#define HOST_IPMI_USERNAME_LEN_MAX	HOST_IPMI_USERNAME_LEN+1
+#define HOST_IPMI_USERNAME_LEN_MAX	utf8_buf_size(HOST_IPMI_USERNAME_LEN)
 #define HOST_IPMI_PASSWORD_LEN		20
-#define HOST_IPMI_PASSWORD_LEN_MAX	HOST_IPMI_PASSWORD_LEN+1
+#define HOST_IPMI_PASSWORD_LEN_MAX	utf8_buf_size(HOST_IPMI_PASSWORD_LEN)
 
 #define INTERFACE_DNS_LEN		64
-#define INTERFACE_DNS_LEN_MAX		INTERFACE_DNS_LEN+1
+#define INTERFACE_DNS_LEN_MAX		utf8_buf_size(INTERFACE_DNS_LEN)
 #define INTERFACE_IP_LEN		39
-#define INTERFACE_IP_LEN_MAX		INTERFACE_IP_LEN+1
+#define INTERFACE_IP_LEN_MAX		utf8_buf_size(INTERFACE_IP_LEN)
 #define INTERFACE_ADDR_LEN		64 /* MAX(INTERFACE_DNS_LEN,INTERFACE_IP_LEN) */
-#define INTERFACE_ADDR_LEN_MAX		INTERFACE_ADDR_LEN+1
+#define INTERFACE_ADDR_LEN_MAX		utf8_buf_size(INTERFACE_ADDR_LEN)
 #define INTERFACE_PORT_LEN		64
-#define INTERFACE_PORT_LEN_MAX		INTERFACE_PORT_LEN+1
+#define INTERFACE_PORT_LEN_MAX		utf8_buf_size(INTERFACE_PORT_LEN)
 
 #define ITEM_NAME_LEN			255
 #define ITEM_KEY_LEN			255
 #define ITEM_SNMP_COMMUNITY_LEN		64
-#define ITEM_SNMP_COMMUNITY_LEN_MAX	ITEM_SNMP_COMMUNITY_LEN+1
+#define ITEM_SNMP_COMMUNITY_LEN_MAX	utf8_buf_size(ITEM_SNMP_COMMUNITY_LEN)
 #define ITEM_SNMP_OID_LEN		255
-#define ITEM_SNMP_OID_LEN_MAX		ITEM_SNMP_OID_LEN+1
+#define ITEM_SNMP_OID_LEN_MAX		utf8_buf_size(ITEM_SNMP_OID_LEN)
 #define ITEM_LASTVALUE_LEN		255
 #define ITEM_ERROR_LEN			128
-#define ITEM_ERROR_LEN_MAX		ITEM_ERROR_LEN+1
+#define ITEM_ERROR_LEN_MAX		utf8_buf_size(ITEM_ERROR_LEN)
 #define ITEM_TRAPPER_HOSTS_LEN		255
-#define ITEM_TRAPPER_HOSTS_LEN_MAX	ITEM_TRAPPER_HOSTS_LEN+1
+#define ITEM_TRAPPER_HOSTS_LEN_MAX	utf8_buf_size(ITEM_TRAPPER_HOSTS_LEN)
 #define ITEM_SNMPV3_SECURITYNAME_LEN		64
-#define ITEM_SNMPV3_SECURITYNAME_LEN_MAX	ITEM_SNMPV3_SECURITYNAME_LEN+1
+#define ITEM_SNMPV3_SECURITYNAME_LEN_MAX	utf8_buf_size(ITEM_SNMPV3_SECURITYNAME_LEN)
 #define ITEM_SNMPV3_AUTHPASSPHRASE_LEN		64
-#define ITEM_SNMPV3_AUTHPASSPHRASE_LEN_MAX	ITEM_SNMPV3_AUTHPASSPHRASE_LEN+1
+#define ITEM_SNMPV3_AUTHPASSPHRASE_LEN_MAX	utf8_buf_size(ITEM_SNMPV3_AUTHPASSPHRASE_LEN)
 #define ITEM_SNMPV3_PRIVPASSPHRASE_LEN		64
-#define ITEM_SNMPV3_PRIVPASSPHRASE_LEN_MAX	ITEM_SNMPV3_PRIVPASSPHRASE_LEN+1
+#define ITEM_SNMPV3_PRIVPASSPHRASE_LEN_MAX	utf8_buf_size(ITEM_SNMPV3_PRIVPASSPHRASE_LEN)
 #define ITEM_LOGTIMEFMT_LEN		64
-#define ITEM_LOGTIMEFMT_LEN_MAX		ITEM_LOGTIMEFMT_LEN+1
+#define ITEM_LOGTIMEFMT_LEN_MAX		utf8_buf_size(ITEM_LOGTIMEFMT_LEN)
 #define ITEM_DELAY_FLEX_LEN		255
-#define ITEM_DELAY_FLEX_LEN_MAX		ITEM_DELAY_FLEX_LEN+1
+#define ITEM_DELAY_FLEX_LEN_MAX		utf8_buf_size(ITEM_DELAY_FLEX_LEN)
 #define ITEM_IPMI_SENSOR_LEN		128
-#define ITEM_IPMI_SENSOR_LEN_MAX	ITEM_IPMI_SENSOR_LEN+1
+#define ITEM_IPMI_SENSOR_LEN_MAX	utf8_buf_size(ITEM_IPMI_SENSOR_LEN)
 #define ITEM_USERNAME_LEN		64
-#define ITEM_USERNAME_LEN_MAX		ITEM_USERNAME_LEN+1
+#define ITEM_USERNAME_LEN_MAX		utf8_buf_size(ITEM_USERNAME_LEN)
 #define ITEM_PASSWORD_LEN		64
-#define ITEM_PASSWORD_LEN_MAX		ITEM_PASSWORD_LEN+1
+#define ITEM_PASSWORD_LEN_MAX		utf8_buf_size(ITEM_PASSWORD_LEN)
 #define ITEM_PUBLICKEY_LEN		64
-#define ITEM_PUBLICKEY_LEN_MAX		ITEM_PUBLICKEY_LEN+1
+#define ITEM_PUBLICKEY_LEN_MAX		utf8_buf_size(ITEM_PUBLICKEY_LEN)
 #define ITEM_PRIVATEKEY_LEN		64
-#define ITEM_PRIVATEKEY_LEN_MAX		ITEM_PRIVATEKEY_LEN+1
+#define ITEM_PRIVATEKEY_LEN_MAX		utf8_buf_size(ITEM_PRIVATEKEY_LEN)
 #if defined(HAVE_IBM_DB2) || defined(HAVE_ORACLE)
 #	define ITEM_PARAM_LEN			2048
 #else
@@ -149,9 +150,9 @@ zbx_graph_item_type;
 #endif
 
 #define FUNCTION_FUNCTION_LEN		12
-#define FUNCTION_FUNCTION_LEN_MAX	FUNCTION_FUNCTION_LEN+1
+#define FUNCTION_FUNCTION_LEN_MAX	utf8_buf_size(FUNCTION_FUNCTION_LEN)
 #define FUNCTION_PARAMETER_LEN		255
-#define FUNCTION_PARAMETER_LEN_MAX	FUNCTION_PARAMETER_LEN+1
+#define FUNCTION_PARAMETER_LEN_MAX	utf8_buf_size(FUNCTION_PARAMETER_LEN)
 
 #define HISTORY_STR_VALUE_LEN		255
 #ifdef HAVE_IBM_DB2
@@ -163,7 +164,7 @@ zbx_graph_item_type;
 #endif
 
 #define HISTORY_LOG_SOURCE_LEN		64
-#define HISTORY_LOG_SOURCE_LEN_MAX	HISTORY_LOG_SOURCE_LEN+1
+#define HISTORY_LOG_SOURCE_LEN_MAX	utf8_buf_size(HISTORY_LOG_SOURCE_LEN)
 
 #define ALERT_SENDTO_LEN		100
 #define ALERT_SUBJECT_LEN		255
@@ -173,21 +174,21 @@ zbx_graph_item_type;
 #	define ALERT_MESSAGE_LEN		65535
 #endif
 #define ALERT_ERROR_LEN			128
-#define ALERT_ERROR_LEN_MAX		ALERT_ERROR_LEN+1
+#define ALERT_ERROR_LEN_MAX		utf8_buf_size(ALERT_ERROR_LEN)
 
 #define GRAPH_NAME_LEN			128
 
 #define GRAPH_ITEM_COLOR_LEN		6
-#define GRAPH_ITEM_COLOR_LEN_MAX	GRAPH_ITEM_COLOR_LEN+1
+#define GRAPH_ITEM_COLOR_LEN_MAX	utf8_buf_size(GRAPH_ITEM_COLOR_LEN)
 
 #define DSERVICE_KEY_LEN		255
 #define DSERVICE_VALUE_LEN		255
-#define DSERVICE_VALUE_LEN_MAX		DSERVICE_VALUE_LEN+1
+#define DSERVICE_VALUE_LEN_MAX		utf8_buf_size(DSERVICE_VALUE_LEN)
 
 #define HTTPTEST_HTTP_USER_LEN		64
-#define HTTPTEST_HTTP_USER_LEN_MAX	HTTPTEST_HTTP_USER_LEN+1
+#define HTTPTEST_HTTP_USER_LEN_MAX	utf8_buf_size(HTTPTEST_HTTP_USER_LEN)
 #define HTTPTEST_HTTP_PASSWORD_LEN	64
-#define HTTPTEST_HTTP_PASSWORD_LEN_MAX	HTTPTEST_HTTP_PASSWORD_LEN+1
+#define HTTPTEST_HTTP_PASSWORD_LEN_MAX	utf8_buf_size(HTTPTEST_HTTP_PASSWORD_LEN)
 
 #define PROXY_DHISTORY_KEY_LEN		255
 #define PROXY_DHISTORY_VALUE_LEN	255
@@ -275,7 +276,7 @@ DB_DSERVICE;
 typedef struct
 {
 	zbx_uint64_t	triggerid;
-	char		description[TRIGGER_DESCRIPTION_LEN * 4 + 1];
+	char		description[utf8_buf_size(TRIGGER_DESCRIPTION_LEN)];
 	char		expression[TRIGGER_EXPRESSION_LEN_MAX];
 	char		*url;
 	char		*comments;
@@ -498,7 +499,7 @@ typedef struct
 {
 	zbx_uint64_t	itemid;	/* itemid should come first for correct sorting */
 	zbx_uint64_t	gitemid;
-	char		key[ITEM_KEY_LEN * 4 + 1];
+	char		key[utf8_buf_size(ITEM_KEY_LEN)];
 	int		drawtype;
 	int		sortorder;
 	char		color[GRAPH_ITEM_COLOR_LEN_MAX];
diff -uNrp zabbix-2.0.10.bk/include/dbcache.h zabbix-2.0.10/include/dbcache.h
--- zabbix-2.0.10.bk/include/dbcache.h	2013-12-09 18:21:41.000000000 +0900
+++ zabbix-2.0.10/include/dbcache.h	2013-12-13 08:47:26.440244442 +0900
@@ -102,7 +102,7 @@ typedef struct
 	unsigned char 	type;
 	unsigned char	data_type;
 	unsigned char	value_type;
-	char		key_orig[ITEM_KEY_LEN * 4 + 1], *key;
+	char		key_orig[utf8_buf_size(ITEM_KEY_LEN)], *key;
 	int		delay;
 	int		nextcheck;
 	int		lastclock;
diff -uNrp zabbix-2.0.10.bk/src/libs/zbxdb/db.c zabbix-2.0.10/src/libs/zbxdb/db.c
--- zabbix-2.0.10.bk/src/libs/zbxdb/db.c	2013-12-09 18:21:41.000000000 +0900
+++ zabbix-2.0.10/src/libs/zbxdb/db.c	2013-12-13 08:52:40.534144784 +0900
@@ -1475,7 +1475,7 @@ DB_ROW	zbx_db_fetch(DB_RESULT result)
 			return NULL;
 		}
 
-		if (result->values_alloc[i] < (alloc = amount * 4 + 1))
+		if (result->values_alloc[i] < (alloc = utf8_buf_size(amount)))
 		{
 			result->values_alloc[i] = alloc;
 			result->values[i] = zbx_realloc(result->values[i], result->values_alloc[i]);
diff -uNrp zabbix-2.0.10.bk/src/libs/zbxdbhigh/proxy.c zabbix-2.0.10/src/libs/zbxdbhigh/proxy.c
--- zabbix-2.0.10.bk/src/libs/zbxdbhigh/proxy.c	2013-12-09 18:21:41.000000000 +0900
+++ zabbix-2.0.10/src/libs/zbxdbhigh/proxy.c	2013-12-13 08:46:56.447967172 +0900
@@ -2186,7 +2186,7 @@ void	process_dhis_data(struct zbx_json_p
 	struct zbx_json_parse	jp_data, jp_row;
 	int			port, status, ret;
 	const char		*p = NULL;
-	char			last_ip[INTERFACE_IP_LEN_MAX], ip[INTERFACE_IP_LEN_MAX], key_[ITEM_KEY_LEN * 4 + 1],
+	char			last_ip[INTERFACE_IP_LEN_MAX], ip[INTERFACE_IP_LEN_MAX], key_[utf8_buf_size(ITEM_KEY_LEN)],
 				tmp[MAX_STRING_LEN], value[DSERVICE_VALUE_LEN_MAX], dns[INTERFACE_DNS_LEN_MAX];
 	time_t			now, hosttime, itemtime;
 
