Skip to content

Commit 0f20e7a

Browse files
committed
Slightly more paranoia and slightly better comments for use of
Windows-specific MultiByteToWideChar/WideCharToMultiByte calls.
1 parent ffd8721 commit 0f20e7a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/backend/utils/adt/oracle_compat.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* 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 $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -187,7 +187,7 @@ win32_utf8_texttowcs(const text *txt)
187187
r = MultiByteToWideChar(CP_UTF8, 0, VARDATA_ANY(txt), nbytes,
188188
result, nbytes);
189189

190-
if (!r) /* assume it's NO_UNICODE_TRANSLATION */
190+
if (r <= 0) /* assume it's NO_UNICODE_TRANSLATION */
191191
{
192192
/* see notes above about error reporting */
193193
pg_verifymbstr(VARDATA_ANY(txt), nbytes, false);
@@ -198,6 +198,7 @@ win32_utf8_texttowcs(const text *txt)
198198
}
199199
}
200200

201+
/* Append trailing null wchar (MultiByteToWideChar won't have) */
201202
Assert(r <= nbytes);
202203
result[r] = 0;
203204

@@ -212,8 +213,9 @@ win32_utf8_wcstotext(const wchar_t *str)
212213
int nbytes;
213214
int r;
214215

216+
/* Compute size of output string (this *will* include trailing null) */
215217
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 */
217219
ereport(ERROR,
218220
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
219221
errmsg("UTF-16 to UTF-8 translation failed: %lu",
@@ -223,7 +225,7 @@ win32_utf8_wcstotext(const wchar_t *str)
223225

224226
r = WideCharToMultiByte(CP_UTF8, 0, str, -1, VARDATA(result), nbytes,
225227
NULL, NULL);
226-
if (r == 0) /* shouldn't happen */
228+
if (r != nbytes) /* shouldn't happen */
227229
ereport(ERROR,
228230
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
229231
errmsg("UTF-16 to UTF-8 translation failed: %lu",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy