diff --git a/libfreerdp/utils/smartcard_pack.c b/libfreerdp/utils/smartcard_pack.c index 3ffc3be73..27ceffe22 100644 --- a/libfreerdp/utils/smartcard_pack.c +++ b/libfreerdp/utils/smartcard_pack.c @@ -352,14 +352,13 @@ static char* smartcard_convert_string_list(const void* in, size_t bytes, BOOL un if (!mszA) return NULL; CopyMemory(mszA, string.sz, bytes - 1); - mszA[bytes - 1] = '\0'; length = bytes - 1; } - for (index = 1; index < length; index++) + for (index = 0; index < length; index++) { - if (mszA[index - 1] == '\0') - mszA[index - 1] = ','; + if (mszA[index] == '\0') + mszA[index] = ','; } return mszA; diff --git a/winpr/libwinpr/crt/unicode.c b/winpr/libwinpr/crt/unicode.c index 5266e9fed..ef9ff5e59 100644 --- a/winpr/libwinpr/crt/unicode.c +++ b/winpr/libwinpr/crt/unicode.c @@ -519,10 +519,10 @@ char* ConvertWCharToUtf8Alloc(const WCHAR* wstr, size_t* pUtfCharLength) *pUtfCharLength = 0; if (rc <= 0) return NULL; - tmp = calloc((size_t)rc + 3ull, sizeof(char)); + tmp = calloc((size_t)rc + 1ull, sizeof(char)); if (!tmp) return NULL; - const SSIZE_T rc2 = ConvertWCharToUtf8(wstr, tmp, (size_t)rc + 2ull); + const SSIZE_T rc2 = ConvertWCharToUtf8(wstr, tmp, (size_t)rc + 1ull); if (rc2 <= 0) { free(tmp); @@ -543,10 +543,10 @@ char* ConvertWCharNToUtf8Alloc(const WCHAR* wstr, size_t wlen, size_t* pUtfCharL *pUtfCharLength = 0; if (rc <= 0) return NULL; - tmp = calloc((size_t)rc + 3ull, sizeof(char)); + tmp = calloc((size_t)rc + 1ull, sizeof(char)); if (!tmp) return NULL; - const SSIZE_T rc2 = ConvertWCharNToUtf8(wstr, wlen, tmp, (size_t)rc + 2ull); + const SSIZE_T rc2 = ConvertWCharNToUtf8(wstr, wlen, tmp, (size_t)rc + 1ull); if (rc2 <= 0) { free(tmp); @@ -567,10 +567,10 @@ char* ConvertMszWCharNToUtf8Alloc(const WCHAR* wstr, size_t wlen, size_t* pUtfCh *pUtfCharLength = 0; if (rc <= 0) return NULL; - tmp = calloc((size_t)rc + 3ull, sizeof(char)); + tmp = calloc((size_t)rc + 1ull, sizeof(char)); if (!tmp) return NULL; - const SSIZE_T rc2 = ConvertMszWCharNToUtf8(wstr, wlen, tmp, (size_t)rc + 2ull); + const SSIZE_T rc2 = ConvertMszWCharNToUtf8(wstr, wlen, tmp, (size_t)rc + 1ull); if (rc2 <= 0) { free(tmp); @@ -590,10 +590,10 @@ WCHAR* ConvertUtf8ToWCharAlloc(const char* str, size_t* pSize) *pSize = 0; if (rc <= 0) return NULL; - tmp = calloc((size_t)rc + 3ull, sizeof(WCHAR)); + tmp = calloc((size_t)rc + 1ull, sizeof(WCHAR)); if (!tmp) return NULL; - const SSIZE_T rc2 = ConvertUtf8ToWChar(str, tmp, (size_t)rc + 2ull); + const SSIZE_T rc2 = ConvertUtf8ToWChar(str, tmp, (size_t)rc + 1ull); if (rc2 <= 0) { free(tmp); @@ -613,10 +613,10 @@ WCHAR* ConvertUtf8NToWCharAlloc(const char* str, size_t len, size_t* pSize) *pSize = 0; if (rc <= 0) return NULL; - tmp = calloc((size_t)rc + 3ull, sizeof(WCHAR)); + tmp = calloc((size_t)rc + 1ull, sizeof(WCHAR)); if (!tmp) return NULL; - const SSIZE_T rc2 = ConvertUtf8NToWChar(str, len, tmp, (size_t)rc + 2ull); + const SSIZE_T rc2 = ConvertUtf8NToWChar(str, len, tmp, (size_t)rc + 1ull); if (rc2 <= 0) { free(tmp); @@ -636,10 +636,10 @@ WCHAR* ConvertMszUtf8NToWCharAlloc(const char* str, size_t len, size_t* pSize) *pSize = 0; if (rc <= 0) return NULL; - tmp = calloc((size_t)rc + 3ull, sizeof(WCHAR)); + tmp = calloc((size_t)rc + 1ull, sizeof(WCHAR)); if (!tmp) return NULL; - const SSIZE_T rc2 = ConvertMszUtf8NToWChar(str, len, tmp, (size_t)rc + 2ull); + const SSIZE_T rc2 = ConvertMszUtf8NToWChar(str, len, tmp, (size_t)rc + 1ull); if (rc2 <= 0) { free(tmp);