summaryrefslogtreecommitdiff
path: root/src/win32/utf-conv.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-04-23 17:28:11 -0700
committerVicent Martí <tanoku@gmail.com>2012-04-23 17:28:11 -0700
commitf9f2344bd4ba6c81a96959509ba59f8563b60265 (patch)
treebb429dc1d066d433ab39076d3369cde56a48bc83 /src/win32/utf-conv.c
parent4795807ad5b4827ff4bdb801641ce8a4d5a8557e (diff)
parent26515e73a11b6f6c25e316ece2a6243aba7af9f5 (diff)
downloadlibgit2-f9f2344bd4ba6c81a96959509ba59f8563b60265.tar.gz
Merge pull request #632 from arrbee/win64-cleanup
Code clean up, including fixing warnings on Windows 64-bit build
Diffstat (limited to 'src/win32/utf-conv.c')
-rw-r--r--src/win32/utf-conv.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/win32/utf-conv.c b/src/win32/utf-conv.c
index f00f5be92..fbcb69d0a 100644
--- a/src/win32/utf-conv.c
+++ b/src/win32/utf-conv.c
@@ -31,27 +31,23 @@ void gitwin_set_utf8(void)
wchar_t* gitwin_to_utf16(const char* str)
{
wchar_t* ret;
- int cb;
+ size_t cb;
if (!str)
return NULL;
cb = strlen(str) * sizeof(wchar_t);
- if (cb == 0) {
- ret = (wchar_t*)git__malloc(sizeof(wchar_t));
- if (ret)
- ret[0] = 0;
- return ret;
- }
+ if (cb == 0)
+ return (wchar_t *)git__calloc(1, sizeof(wchar_t));
/* Add space for null terminator */
cb += sizeof(wchar_t);
- ret = (wchar_t*)git__malloc(cb);
+ ret = (wchar_t *)git__malloc(cb);
if (!ret)
return NULL;
- if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, cb) == 0) {
+ if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, (int)cb) == 0) {
giterr_set(GITERR_OS, "Could not convert string to UTF-16");
git__free(ret);
ret = NULL;
@@ -62,7 +58,7 @@ wchar_t* gitwin_to_utf16(const char* str)
int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
{
- int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, len);
+ int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, (int)len);
if (result == 0)
giterr_set(GITERR_OS, "Could not convert string to UTF-16");
return result;
@@ -71,19 +67,14 @@ int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
char* gitwin_from_utf16(const wchar_t* str)
{
char* ret;
- int cb;
+ size_t cb;
- if (!str) {
+ if (!str)
return NULL;
- }
cb = wcslen(str) * sizeof(char);
- if (cb == 0) {
- ret = (char*)git__malloc(sizeof(char));
- if (ret)
- ret[0] = 0;
- return ret;
- }
+ if (cb == 0)
+ return (char *)git__calloc(1, sizeof(char));
/* Add space for null terminator */
cb += sizeof(char);
@@ -92,7 +83,7 @@ char* gitwin_from_utf16(const wchar_t* str)
if (!ret)
return NULL;
- if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, cb, NULL, NULL) == 0) {
+ if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, (int)cb, NULL, NULL) == 0) {
giterr_set(GITERR_OS, "Could not convert string to UTF-8");
git__free(ret);
ret = NULL;