summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/miscfuncs.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/miscfuncs.cc')
-rw-r--r--winsup/cygwin/miscfuncs.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index 26686bd2b..0f5804ed6 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -210,10 +210,18 @@ get_cp ()
return current_codepage == ansi_cp ? GetACP() : GetOEMCP();
}
+/* tlen is always treated as the maximum buffer size, including the '\0'
+ character. sys_wcstombs will always return a 0-terminated result, no
+ matter what. */
int __stdcall
-sys_wcstombs (char *tgt, const WCHAR *src, int len)
+sys_wcstombs (char *tgt, int tlen, const WCHAR *src, int slen)
{
- return WideCharToMultiByte (get_cp (), 0, src, -1, tgt, len, NULL, NULL);
+ int ret;
+
+ ret = WideCharToMultiByte (get_cp (), 0, src, slen, tgt, tlen, NULL, NULL);
+ if (ret)
+ tgt[ret < tlen ? ret : tlen - 1] = '\0';
+ return ret;
}
int __stdcall