fixed review issues

* Overallocation in unicode functions
* Removed useless statements
* Fixed loop indices
This commit is contained in:
akallabeth 2022-11-24 18:42:45 +01:00 committed by akallabeth
parent 40b55466bf
commit 66dad5deae
2 changed files with 15 additions and 16 deletions

View File

@ -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;

View File

@ -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);