[Pcsclite-cvs-commit] r3016 - /trunk/PCSC/src/winscard_clnt.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Jun 24 08:15:46 UTC 2008


Author: rousseau
Date: Tue Jun 24 08:15:45 2008
New Revision: 3016

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=3016
Log:
SCardListReaderGroups(): add support of SCARD_AUTOALLOCATE

Modified:
    trunk/PCSC/src/winscard_clnt.c

Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=3016&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Tue Jun 24 08:15:45 2008
@@ -3253,11 +3253,13 @@
 {
 	LONG rv = SCARD_S_SUCCESS;
 	LONG dwContextIndex;
+	char *buf = NULL;
 
 	PROFILE_START
 
-	const char ReaderGroup[] = "SCard$DefaultReaders";
-	const int dwGroups = strlen(ReaderGroup) + 2;
+	/* Multi-string with two trailing \0 */
+	const char ReaderGroup[] = "SCard$DefaultReaders\0";
+	const int dwGroups = sizeof(ReaderGroup);
 
 	rv = SCardCheckDaemonAvailability();
 	if (rv != SCARD_S_SUCCESS)
@@ -3280,20 +3282,30 @@
 		 * -> so the mMutex has been unlocked */
 		return SCARD_E_INVALID_HANDLE;
 
-	if (mszGroups)
-	{
+	if (SCARD_AUTOALLOCATE == *pcchGroups)
+	{
+		buf = malloc(dwGroups);
+		if (NULL == buf)
+		{
+			rv = SCARD_E_NO_MEMORY;
+			goto end;
+		}
+		*(char **)mszGroups = buf;
+	}
+	else
+	{
+		buf = mszGroups;
 
 		if (*pcchGroups < dwGroups)
 			rv = SCARD_E_INSUFFICIENT_BUFFER;
-		else
-		{
-			memset(mszGroups, 0, dwGroups);
-			memcpy(mszGroups, ReaderGroup, strlen(ReaderGroup));
-		}
-	}
+	}
+
+	if (buf)
+		memcpy(buf, ReaderGroup, dwGroups);
 
 	*pcchGroups = dwGroups;
 
+end:
 	SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
 
 	PROFILE_END(rv)




More information about the Pcsclite-cvs-commit mailing list