9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.74 2007/11/15 21:14:39 momjian Exp $
12
+ * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.75 2007/11/24 21:16:55 tgl Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -187,7 +187,7 @@ win32_utf8_texttowcs(const text *txt)
187
187
r = MultiByteToWideChar (CP_UTF8 , 0 , VARDATA_ANY (txt ), nbytes ,
188
188
result , nbytes );
189
189
190
- if (! r ) /* assume it's NO_UNICODE_TRANSLATION */
190
+ if (r <= 0 ) /* assume it's NO_UNICODE_TRANSLATION */
191
191
{
192
192
/* see notes above about error reporting */
193
193
pg_verifymbstr (VARDATA_ANY (txt ), nbytes , false);
@@ -198,6 +198,7 @@ win32_utf8_texttowcs(const text *txt)
198
198
}
199
199
}
200
200
201
+ /* Append trailing null wchar (MultiByteToWideChar won't have) */
201
202
Assert (r <= nbytes );
202
203
result [r ] = 0 ;
203
204
@@ -212,8 +213,9 @@ win32_utf8_wcstotext(const wchar_t *str)
212
213
int nbytes ;
213
214
int r ;
214
215
216
+ /* Compute size of output string (this *will* include trailing null) */
215
217
nbytes = WideCharToMultiByte (CP_UTF8 , 0 , str , -1 , NULL , 0 , NULL , NULL );
216
- if (nbytes = = 0 ) /* shouldn't happen */
218
+ if (nbytes < = 0 ) /* shouldn't happen */
217
219
ereport (ERROR ,
218
220
(errcode (ERRCODE_CHARACTER_NOT_IN_REPERTOIRE ),
219
221
errmsg ("UTF-16 to UTF-8 translation failed: %lu" ,
@@ -223,7 +225,7 @@ win32_utf8_wcstotext(const wchar_t *str)
223
225
224
226
r = WideCharToMultiByte (CP_UTF8 , 0 , str , -1 , VARDATA (result ), nbytes ,
225
227
NULL , NULL );
226
- if (r == 0 ) /* shouldn't happen */
228
+ if (r != nbytes ) /* shouldn't happen */
227
229
ereport (ERROR ,
228
230
(errcode (ERRCODE_CHARACTER_NOT_IN_REPERTOIRE ),
229
231
errmsg ("UTF-16 to UTF-8 translation failed: %lu" ,
0 commit comments