You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2013/10/21 12:31:45 UTC
svn commit: r1534083 - in /subversion/trunk/subversion/libsvn_subr:
config_win.c nls.c
Author: rhuijben
Date: Mon Oct 21 10:31:45 2013
New Revision: 1534083
URL: http://svn.apache.org/r1534083
Log:
Simplify some Win32 specific code by using svn_subr__win32_utf16_to_utf8.
* subversion/libsvn_subr/config_win.c
(includes): Add private/svn_subr_private.h.
(svn_config__win_config_path): Use svn_subr__win32_utf16_to_utf8.
(parse_section): Add comment.
* subversion/libsvn_subr/nls.c
(includes): Add svn_subr_private.h.
(svn_nls_init): Simplify win32 specific code. Assume Windows 2000
or later. Report buffer overflows instead of using a truncated
path.
Modified:
subversion/trunk/subversion/libsvn_subr/config_win.c
subversion/trunk/subversion/libsvn_subr/nls.c
Modified: subversion/trunk/subversion/libsvn_subr/config_win.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/config_win.c?rev=1534083&r1=1534082&r2=1534083&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/config_win.c (original)
+++ subversion/trunk/subversion/libsvn_subr/config_win.c Mon Oct 21 10:31:45 2013
@@ -44,10 +44,11 @@
#include "svn_path.h"
#include "svn_pools.h"
#include "svn_utf.h"
+#include "private/svn_subr_private.h"
svn_error_t *
svn_config__win_config_path(const char **folder, int system_path,
- apr_pool_t *pool)
+ apr_pool_t *result_pool)
{
/* ### Adding CSIDL_FLAG_CREATE here, because those folders really
must exist. I'm not too sure about the SHGFP_TYPE_CURRENT
@@ -56,8 +57,6 @@ svn_config__win_config_path(const char *
| CSIDL_FLAG_CREATE);
WCHAR folder_ucs2[MAX_PATH];
- int inwords, outbytes, outlength;
- char *folder_utf8;
if (S_OK != SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT,
folder_ucs2))
@@ -66,26 +65,8 @@ svn_config__win_config_path(const char *
? "Can't determine the system config path"
: "Can't determine the user's config path"));
- /* ### When mapping from UCS-2 to UTF-8, we need at most 3 bytes
- per wide char, plus extra space for the nul terminator. */
- inwords = lstrlenW(folder_ucs2);
- outbytes = outlength = 3 * (inwords + 1);
-
- folder_utf8 = apr_palloc(pool, outlength);
-
- outbytes = WideCharToMultiByte(CP_UTF8, 0, folder_ucs2, inwords,
- folder_utf8, outbytes, NULL, NULL);
-
- if (outbytes == 0)
- return svn_error_wrap_apr(apr_get_os_error(),
- "Can't convert config path to UTF-8");
-
- /* Note that WideCharToMultiByte does _not_ terminate the
- outgoing buffer. */
- folder_utf8[outbytes] = '\0';
- *folder = folder_utf8;
-
- return SVN_NO_ERROR;
+ return svn_error_trace(svn_subr__win32_utf16_to_utf8(folder, folder_ucs2,
+ result_pool));
}
@@ -97,6 +78,8 @@ svn_config__win_config_path(const char *
#define SVN_REG_DEFAULT_NAME_SIZE 2048
#define SVN_REG_DEFAULT_VALUE_SIZE 8192
+/* ### This function should be converted to use the unicode functions
+ ### instead of the ansi functions */
static svn_error_t *
parse_section(svn_config_t *cfg, HKEY hkey, const char *section,
svn_stringbuf_t *option, svn_stringbuf_t *value)
Modified: subversion/trunk/subversion/libsvn_subr/nls.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/nls.c?rev=1534083&r1=1534082&r2=1534083&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/nls.c (original)
+++ subversion/trunk/subversion/libsvn_subr/nls.c Mon Oct 21 10:31:45 2013
@@ -37,6 +37,8 @@
#include "svn_pools.h"
#include "svn_path.h"
+#include "private/svn_subr_private.h"
+
#include "svn_private_config.h"
svn_error_t *
@@ -53,69 +55,38 @@ svn_nls_init(void)
{
#ifdef WIN32
WCHAR ucs2_path[MAX_PATH];
- char* utf8_path;
+ const char* utf8_path;
const char* internal_path;
- apr_pool_t* pool;
- apr_size_t inwords, outbytes, outlength;
+ apr_pool_t* scratch_pool;
- pool = svn_pool_create(0);
+ scratch_pool = svn_pool_create(NULL);
/* get exe name - our locale info will be in '../share/locale' */
- inwords = GetModuleFileNameW(0, ucs2_path,
- sizeof(ucs2_path) / sizeof(ucs2_path[0]));
- if (! inwords)
+ GetModuleFileNameW(NULL, ucs2_path,
+ sizeof(ucs2_path) / sizeof(ucs2_path[0]))
+ if (apr_get_os_error())
{
- /* We must be on a Win9x machine, so attempt to get an ANSI path,
- and convert it to Unicode. */
- CHAR ansi_path[MAX_PATH];
-
- if (GetModuleFileNameA(0, ansi_path, sizeof(ansi_path)))
- {
- inwords =
- MultiByteToWideChar(CP_ACP, 0, ansi_path, -1, ucs2_path,
- sizeof(ucs2_path) / sizeof(ucs2_path[0]));
- if (! inwords)
- {
- err =
- svn_error_createf(APR_EINVAL, NULL,
- _("Can't convert string to UCS-2: '%s'"),
- ansi_path);
- }
- }
- else
- {
- err = svn_error_create(APR_EINVAL, NULL,
- _("Can't get module file name"));
- }
+ err = svn_error_wrap_apr(apr_get_os_error()
+ _("Can't get module file name"));
}
if (! err)
- {
- outbytes = outlength = 3 * (inwords + 1);
- utf8_path = apr_palloc(pool, outlength);
-
- outbytes = WideCharToMultiByte(CP_UTF8, 0, ucs2_path, inwords,
- utf8_path, outbytes, NULL, NULL);
+ err = svn_subr__win32_utf16_to_utf8(&utf8_path, ucs2_path,
+ scratch_pool);
- if (outbytes == 0)
- {
- err = svn_error_wrap_apr(apr_get_os_error(),
- _("Can't convert module path "
- "to UTF-8 from UCS-2: '%s'"),
- ucs2_path);
- }
- else
- {
- utf8_path[outlength - outbytes] = '\0';
- internal_path = svn_dirent_internal_style(utf8_path, pool);
- /* get base path name */
- internal_path = svn_dirent_dirname(internal_path, pool);
- internal_path = svn_dirent_join(internal_path,
- SVN_LOCALE_RELATIVE_PATH,
- pool);
- bindtextdomain(PACKAGE_NAME, internal_path);
- }
+ if (! err)
+ {
+ internal_path = svn_dirent_internal_style(utf8_path, scratch_pool);
+ /* get base path name */
+ internal_path = svn_dirent_dirname(internal_path, scratch_pool);
+ internal_path = svn_dirent_join(internal_path,
+ SVN_LOCALE_RELATIVE_PATH,
+ scratch_pool);
+ SVN_ERR(svn_dirent_get_absolute(&internal_path, internal_path,
+ scratch_pool));
+ bindtextdomain(PACKAGE_NAME, internal_path);
}
- svn_pool_destroy(pool);
+
+ svn_pool_destroy(scratch_pool);
}
#else /* ! WIN32 */
bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);