From 2b52c294a2fbfcfdf23489c80baca060f258c453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 10 Apr 2014 17:36:42 -0400 Subject: [PATCH] channels/smartcard: minor fixes --- .../smartcard/client/smartcard_operations.c | 22 +++++++++---------- channels/smartcard/client/smartcard_pack.c | 4 ++-- winpr/libwinpr/smartcard/smartcard_pcsc.c | 8 +++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index 17004b078..ec665b4b2 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -258,12 +258,12 @@ static UINT32 smartcard_ListReadersA(SMARTCARD_DEVICE* smartcard, IRP* irp) status = ret.ReturnCode = SCardListReadersA(hContext, (LPCSTR) call.mszGroups, (LPSTR) &mszReaders, &cchReaders); - if (status) - return status; - ret.msz = (BYTE*) mszReaders; ret.cBytes = cchReaders; + if (status) + return status; + status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret); if (status) @@ -298,12 +298,12 @@ static UINT32 smartcard_ListReadersW(SMARTCARD_DEVICE* smartcard, IRP* irp) status = ret.ReturnCode = SCardListReadersW(hContext, (LPCWSTR) call.mszGroups, (LPWSTR) &mszReaders, &cchReaders); + ret.msz = (BYTE*) mszReaders; + ret.cBytes = cchReaders * 2; + if (status) return status; - ret.msz = (BYTE*) mszReaders; - ret.cBytes = cchReaders; - status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret); if (status) @@ -753,7 +753,7 @@ static DWORD smartcard_StatusA(SMARTCARD_DEVICE* smartcard, IRP* irp) } ret.mszReaderNames = (BYTE*) mszReaderNames; - ret.cBytes = smartcard_multi_string_length_a((char*) ret.mszReaderNames) + 2; + ret.cBytes = cchReaderLen * 2; status = smartcard_pack_status_return(smartcard, irp->output, &ret); @@ -802,7 +802,7 @@ static DWORD smartcard_StatusW(SMARTCARD_DEVICE* smartcard, IRP* irp) } ret.mszReaderNames = (BYTE*) mszReaderNames; - ret.cBytes = (smartcard_multi_string_length_w((WCHAR*) ret.mszReaderNames) + 2) * 2; + ret.cBytes = cchReaderLen * 2; status = smartcard_pack_status_return(smartcard, irp->output, &ret); @@ -937,7 +937,7 @@ static UINT32 smartcard_GetAttrib(SMARTCARD_DEVICE* smartcard, IRP* irp) call.cbAttrLen = 0; if (call.cbAttrLen) - ret.pbAttr = malloc(call.cbAttrLen); + ret.pbAttr = (BYTE*) malloc(call.cbAttrLen); cbAttrLen = call.cbAttrLen; @@ -1303,7 +1303,7 @@ void smartcard_irp_device_control(SMARTCARD_DEVICE* smartcard, IRP* irp) smartcard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, result); } - if (Stream_GetPosition(irp->input) < Stream_Length(irp->input)) + if (((size_t) Stream_GetPosition(irp->input)) < Stream_Length(irp->input)) { UINT32 difference; @@ -1317,7 +1317,7 @@ void smartcard_irp_device_control(SMARTCARD_DEVICE* smartcard, IRP* irp) winpr_HexDump(Stream_Pointer(irp->input), difference); } - if (Stream_GetPosition(irp->input) > Stream_Length(irp->input)) + if (((size_t) Stream_GetPosition(irp->input)) > Stream_Length(irp->input)) { UINT32 difference; diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index b1b66f4b9..d3fa7ce11 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -807,7 +807,7 @@ UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wS return STATUS_BUFFER_TOO_SMALL; } - readerState->szReader = malloc(count + 1); + readerState->szReader = (unsigned char*) malloc(count + 1); Stream_Read(s, readerState->szReader, count); smartcard_unpack_read_size_align(smartcard, s, count, 4); readerState->szReader[count] = '\0'; @@ -913,7 +913,7 @@ UINT32 smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wS return STATUS_BUFFER_TOO_SMALL; } - readerState->szReader = malloc((count + 1) * 2); + readerState->szReader = (WCHAR*) malloc((count + 1) * 2); Stream_Read(s, readerState->szReader, (count * 2)); smartcard_unpack_read_size_align(smartcard, s, (count * 2), 4); readerState->szReader[count] = '\0'; diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 30bbbfc2d..8938add49 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -453,7 +453,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardListReadersW(SCARDCONTEXT hContext, if (status && *pMszReadersA) { - *pcchReaders = ConvertToUnicode(CP_UTF8, 0, *pMszReadersA, *pcchReaders, (WCHAR**) mszReaders, 0) * 2; + *pcchReaders = ConvertToUnicode(CP_UTF8, 0, *pMszReadersA, *pcchReaders, (WCHAR**) mszReaders, 0); PCSC_AddMemoryBlock(hContext, mszReaders); } @@ -466,7 +466,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardListReadersW(SCARDCONTEXT hContext, if (mszReadersA) { - *pcchReaders = ConvertToUnicode(CP_UTF8, 0, mszReadersA, *pcchReaders, (WCHAR**) mszReaders, 0) * 2; + *pcchReaders = ConvertToUnicode(CP_UTF8, 0, mszReadersA, *pcchReaders, (WCHAR**) mszReaders, 0); PCSC_AddMemoryBlock(hContext, mszReaders); PCSC_SCardFreeMemory(hContext, mszReadersA); @@ -1120,7 +1120,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatusW(SCARDHANDLE hCard, if (mszReaderNamesA) { - *pcchReaderLen = ConvertToUnicode(CP_UTF8, 0, mszReaderNamesA, *pcchReaderLen, (WCHAR**) mszReaderNames, 0) * 2; + *pcchReaderLen = ConvertToUnicode(CP_UTF8, 0, mszReaderNamesA, *pcchReaderLen, (WCHAR**) mszReaderNames, 0); PCSC_AddMemoryBlock(hContext, mszReaderNames); PCSC_SCardFreeMemory(hContext, mszReaderNamesA); @@ -1295,7 +1295,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L int length; WCHAR* pbAttrW = NULL; - length = ConvertToUnicode(CP_UTF8, 0, (char*) pbAttr, *pcbAttrLen, &pbAttrW, 0) * 2; + length = ConvertToUnicode(CP_UTF8, 0, (char*) pbAttr, *pcbAttrLen, &pbAttrW, 0); PCSC_SCardFreeMemory(hContext, pbAttrA);