[Pcsclite-git-commit] [PCSC] 01/02: Fix compiler warning (gcc 7)

Ludovic Rousseau rousseau at moszumanska.debian.org
Mon Aug 21 15:48:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository PCSC.

commit 5905bbe11414c131a32a7d84829eaa5d060bd55d
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Mon Aug 21 13:10:52 2017 +0200

    Fix compiler warning (gcc 7)
    
    Use an intermediate variable nbSlots.
    
    readerfactory.c: In function ‘RFAddReader’:
    readerfactory.c:457:51: warning: ‘%02X’ directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
       snprintf(tmpReader + strlen(tmpReader) - 2, 3, "%02X", j);
                                                       ^~~~
    readerfactory.c:457:50: note: directive argument in the range [1, 2147483646]
       snprintf(tmpReader + strlen(tmpReader) - 2, 3, "%02X", j);
                                                      ^~~~~~
    In file included from /usr/include/stdio.h:938:0,
                     from readerfactory.c:43:
    /usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 3 and 9 bytes into a destination of size 3
       return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            __bos (__s), __fmt, __va_arg_pack ());
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 src/readerfactory.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/readerfactory.c b/src/readerfactory.c
index ef0e673..3e2fdb6 100644
--- a/src/readerfactory.c
+++ b/src/readerfactory.c
@@ -410,12 +410,13 @@ LONG RFAddReader(const char *readerNameLong, int port, const char *library,
 	rv = IFDGetCapabilities((sReadersContexts[dwContext]),
 		TAG_IFD_SLOTS_NUMBER, &dwGetSize, ucGetData);
 
-	if (rv != IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
+	int nbSlots = ucGetData[0];
+	if (rv != IFD_SUCCESS || dwGetSize != 1 || nbSlots == 0)
 		/* Reader does not have this defined.  Must be a single slot
 		 * reader so we can just return SCARD_S_SUCCESS. */
 		return SCARD_S_SUCCESS;
 
-	if (rv == IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
+	if (rv == IFD_SUCCESS && dwGetSize == 1 && nbSlots == 1)
 		/* Reader has this defined and it only has one slot */
 		return SCARD_S_SUCCESS;
 
@@ -425,7 +426,7 @@ LONG RFAddReader(const char *readerNameLong, int port, const char *library,
 	 */
 
 	/* Initialize the rest of the slots */
-	for (j = 1; j < ucGetData[0]; j++)
+	for (j = 1; j < nbSlots; j++)
 	{
 		char *tmpReader = NULL;
 		DWORD dwContextB = 0;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git



More information about the Pcsclite-cvs-commit mailing list