]> granicus.if.org Git - postgresql/commitdiff
Fix failure of new wchar->mb functions to advance from pointer.
authorRobert Haas <rhaas@postgresql.org>
Fri, 6 Jul 2012 03:47:53 +0000 (23:47 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 6 Jul 2012 03:47:53 +0000 (23:47 -0400)
Bug spotted by Tom Lane.

src/backend/utils/mb/wchar.c

index 1755be5ebfa4e30def40aedd647232de97f74b3f..54581cd12a5e98a97b0593b8d74e1db8aa26a1f6 100644 (file)
@@ -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;