[Pcsclite-cvs-commit] r2909 - /trunk/PCSC/src/testpcsc.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Thu Apr 24 09:31:47 UTC 2008
Author: rousseau
Date: Thu Apr 24 09:31:46 2008
New Revision: 2909
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=2909
Log:
better management of corner cases
Modified:
trunk/PCSC/src/testpcsc.c
Modified: trunk/PCSC/src/testpcsc.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/testpcsc.c?rev=2909&op=diff
==============================================================================
--- trunk/PCSC/src/testpcsc.c (original)
+++ trunk/PCSC/src/testpcsc.c Thu Apr 24 09:31:46 2008
@@ -57,11 +57,11 @@
SCARDCONTEXT hContext;
SCARD_READERSTATE_A rgReaderStates[1];
DWORD dwReaderLen, dwState, dwProt, dwAtrLen;
- DWORD dwPref, dwReaders;
+ DWORD dwPref, dwReaders = 0;
char *pcReaders, *mszReaders;
unsigned char pbAtr[MAX_ATR_SIZE];
char *mszGroups;
- DWORD dwGroups;
+ DWORD dwGroups = 0;
long rv;
DWORD i;
int p, iReader;
@@ -100,7 +100,7 @@
test_rv(rv, hContext, PANIC);
printf("Testing SCardListReaderGroups\t: ");
- mszGroups = malloc(sizeof(char) * dwGroups);
+ mszGroups = calloc(dwGroups, sizeof(char));
rv = SCardListReaderGroups(hContext, mszGroups, &dwGroups);
test_rv(rv, hContext, PANIC);
@@ -108,7 +108,7 @@
* Have to understand the multi-string here
*/
p = 0;
- for (i = 0; i < dwGroups - 1; i++)
+ for (i = 0; i+1 < dwGroups; i++)
{
++p;
printf(GREEN "Group %02d: %s\n" NORMAL, p, &mszGroups[i]);
@@ -124,7 +124,7 @@
test_rv(rv, hContext, PANIC);
printf("Testing SCardListReaders\t: ");
- mszReaders = malloc(sizeof(char) * dwReaders);
+ mszReaders = calloc(dwReaders, sizeof(char));
rv = SCardListReaders(hContext, mszGroups, mszReaders, &dwReaders);
test_rv(rv, hContext, PANIC);
@@ -132,7 +132,7 @@
* Have to understand the multi-string here
*/
p = 0;
- for (i = 0; i < dwReaders - 1; i++)
+ for (i = 0; i+1 < dwReaders; i++)
{
++p;
printf(GREEN "Reader %02d: %s\n" NORMAL, p, &mszReaders[i]);
More information about the Pcsclite-cvs-commit
mailing list