From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 6 Jul 2012 03:47:53 +0000 (-0400)
Subject: Fix failure of new wchar->mb functions to advance from pointer.
X-Git-Tag: REL9_3_BETA1~1229
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f6a05fd973a102f7e66c491d3f854864b8d24844;p=postgresql

Fix failure of new wchar->mb functions to advance from pointer.

Bug spotted by Tom Lane.
---

diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c
index 1755be5ebf..54581cd12a 100644
--- a/src/backend/utils/mb/wchar.c
+++ b/src/backend/utils/mb/wchar.c
@@ -380,6 +380,7 @@ pg_wchar2euc_with_len(const pg_wchar *from, unsigned char *to, int len)
 			*to++ = *from;
 			cnt++;
 		}		
+		from++;
 		len--;
 	}
 	*to = 0;
@@ -518,9 +519,10 @@ pg_wchar2utf_with_len(const pg_wchar *from, unsigned char *to, int len)
 		
 		unicode_to_utf8(*from, to);
 		char_len = pg_utf_mblen(to);
-		len--;
 		cnt += char_len;
 		to += char_len;
+		from++;
+		len--;
 	}
 	*to = 0;
 	return cnt;
@@ -854,6 +856,7 @@ pg_wchar2mule_with_len(const pg_wchar *from, unsigned char *to, int len)
 			*to++ = lb;
 			cnt += 1;
 		}
+		from++;
 		len--;
 	}
 	*to = 0;