From f0acc73541c250a7234a5e2addac79369cf22859 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 12 Jan 2010 12:36:43 +0000 Subject: [PATCH] Fix compilation warnings. Fix Issue 52. --- src/examples/nfc-anticol.c | 2 +- src/examples/nfc-mfclassic.c | 54 ++++++++++++++++++------------------ src/lib/bitutils.c | 20 ++++++------- src/lib/drivers/acr122.c | 2 -- src/lib/drivers/pn532_uart.c | 2 +- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/examples/nfc-anticol.c b/src/examples/nfc-anticol.c index d0647cd..5c371ad 100644 --- a/src/examples/nfc-anticol.c +++ b/src/examples/nfc-anticol.c @@ -118,7 +118,7 @@ int main(int argc,char* argv[]) print_usage(argv); return 0; } else if (0 == strcmp(argv[arg], "-q")) { - INFO("Quiet mode."); + INFO("%s", "Quiet mode."); quiet_output = true; } else { ERR("%s is not supported option.", argv[arg]); diff --git a/src/examples/nfc-mfclassic.c b/src/examples/nfc-mfclassic.c index f04b00d..567586f 100644 --- a/src/examples/nfc-mfclassic.c +++ b/src/examples/nfc-mfclassic.c @@ -1,4 +1,4 @@ -/** +/*- * Public platform independent Near Field Communication (NFC) library * * Copyright (C) 2009, Roel Verdult @@ -15,10 +15,11 @@ * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see - * - * - * @file nfc-mftool.c - * @brief + */ + +/** + * @file nfc-mfclassic.c + * @brief MIFARE Classic manipulation example */ #include @@ -311,8 +312,8 @@ void mifare_classic_extract_payload(const char* abDump, char* pbPayload) typedef enum { ACTION_READ, ACTION_WRITE, - ACTION_EXPLAIN, - ACTION_EXTRACT + ACTION_EXTRACT, + ACTION_USAGE } action_t; void print_usage(const char* pcProgramName) @@ -333,17 +334,15 @@ void print_usage(const char* pcProgramName) int main(int argc, const char* argv[]) { bool b4K; - action_t atAction; + action_t atAction = ACTION_USAGE; byte_t* pbtUID; FILE* pfKeys = NULL; FILE* pfDump = NULL; - // printf("Checking arguments and settings\n"); - if(argc < 2) { print_usage(argv[0]); - return 1; + exit(EXIT_FAILURE); } const char* command = argv[1]; @@ -357,21 +356,22 @@ int main(int argc, const char* argv[]) atAction = ACTION_WRITE; bUseKeyA = (tolower(*(argv[2])) == 'a'); bUseKeyFile = (argc > 4); - } else if(strcmp(command, "e") == 0) - { - atAction = ACTION_EXPLAIN; } else if(strcmp(command, "x") == 0) { atAction = ACTION_EXTRACT; } switch(atAction) { + case ACTION_USAGE: + print_usage(argv[0]); + exit(EXIT_FAILURE); + break; case ACTION_READ: case ACTION_WRITE: if (argc < 4) { print_usage(argv[0]); - return 1; + exit(EXIT_FAILURE); } if (bUseKeyFile) @@ -380,13 +380,13 @@ int main(int argc, const char* argv[]) if (pfKeys == NULL) { printf("Could not open keys file: %s\n",argv[4]); - return 1; + exit(EXIT_FAILURE); } if (fread(&mtKeys,1,sizeof(mtKeys),pfKeys) != sizeof(mtKeys)) { printf("Could not read keys file: %s\n",argv[4]); fclose(pfKeys); - return 1; + exit(EXIT_FAILURE); } fclose(pfKeys); } @@ -399,14 +399,14 @@ int main(int argc, const char* argv[]) if (pfDump == NULL) { printf("Could not open dump file: %s\n",argv[3]); - return 1; + exit(EXIT_FAILURE); } if (fread(&mtDump,1,sizeof(mtDump),pfDump) != sizeof(mtDump)) { printf("Could not read dump file: %s\n",argv[3]); fclose(pfDump); - return 1; + exit(EXIT_FAILURE); } fclose(pfDump); } @@ -417,7 +417,7 @@ int main(int argc, const char* argv[]) if (pnd == NULL) { printf("Error connecting NFC reader\n"); - return 1; + exit(EXIT_FAILURE); } nfc_initiator_init(pnd); @@ -440,7 +440,7 @@ int main(int argc, const char* argv[]) { printf("Error: no tag was found\n"); nfc_disconnect(pnd); - return 1; + exit(EXIT_FAILURE); } // Test if we are dealing with a MIFARE compatible tag @@ -448,7 +448,7 @@ int main(int argc, const char* argv[]) { printf("Error: tag is not a MIFARE Classic card\n"); nfc_disconnect(pnd); - return 1; + exit(EXIT_FAILURE); } if (bUseKeyFile) @@ -481,7 +481,7 @@ int main(int argc, const char* argv[]) if (fwrite(&mtDump,1,sizeof(mtDump),pfDump) != sizeof(mtDump)) { printf("\nCould not write to file: %s\n",argv[3]); - return 1; + exit(EXIT_FAILURE); } printf("Done.\n"); fclose(pfDump); @@ -508,14 +508,14 @@ int main(int argc, const char* argv[]) if (pfDump == NULL) { printf("Could not open dump file: %s\n",pcDump); - return 1; + exit(EXIT_FAILURE); } if (fread(abDump,1,sizeof(abDump),pfDump) != sizeof(abDump)) { printf("Could not read dump file: %s\n",pcDump); fclose(pfDump); - return 1; + exit(EXIT_FAILURE); } fclose(pfDump); @@ -526,13 +526,13 @@ int main(int argc, const char* argv[]) if (fwrite(abPayload,1,sizeof(abPayload),pfPayload) != sizeof(abPayload)) { printf("Could not write to file: %s\n",pcPayload); - return 1; + exit(EXIT_FAILURE); } fclose(pfPayload); printf("Done, all bytes have been extracted!\n"); } }; - return 0; + exit(EXIT_SUCCESS); } diff --git a/src/lib/bitutils.c b/src/lib/bitutils.c index 71dc29a..244f1c9 100644 --- a/src/lib/bitutils.c +++ b/src/lib/bitutils.c @@ -160,15 +160,15 @@ void print_hex_bits(const byte_t* pbtData, const size_t szBits) printf("%02x ",pbtData[szPos]); } + uint8_t uRemainder = szBits % 8; // Print the rest bits - if (szBits%8 != 0) + if (uRemainder != 0) { - if (szBits%8 < 5) - printf("%01x (%i bits)",pbtData[szBytes], szBits%8); + if (uRemainder < 5) + printf("%01x (%d bits)",pbtData[szBytes], uRemainder); else - printf("%02x (%i bits)",pbtData[szBytes], szBits%8); + printf("%02x (%d bits)",pbtData[szBytes], uRemainder); } - printf("\n"); } @@ -188,15 +188,15 @@ void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbt } } + uint8_t uRemainder = szBits % 8; // Print the rest bits, these cannot have parity bit - if (szBits%8 != 0) + if (uRemainder != 0) { - if (szBits%8 < 5) - printf("%01x (%i bits)",pbtData[szBytes], szBits%8); + if (uRemainder < 5) + printf("%01x (%d bits)",pbtData[szBytes], uRemainder); else - printf("%02x (%i bits)",pbtData[szBytes], szBits%8); + printf("%02x (%d bits)",pbtData[szBytes], uRemainder); } - printf("\n"); } diff --git a/src/lib/drivers/acr122.c b/src/lib/drivers/acr122.c index 580b8b2..df9bdf5 100644 --- a/src/lib/drivers/acr122.c +++ b/src/lib/drivers/acr122.c @@ -133,7 +133,6 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p size_t szPos = 0; char acDeviceNames[256+64*DRIVERS_MAX_DEVICES]; size_t szDeviceNamesLen = sizeof(acDeviceNames); - acr122_spec_t as; uint32_t uiBusIndex = 0; SCARDCONTEXT *pscc; @@ -178,7 +177,6 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p { DBG("PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos); } - SCardDisconnect(as.hCard,SCARD_LEAVE_CARD); // Find next device name position while (acDeviceNames[szPos++] != '\0'); diff --git a/src/lib/drivers/pn532_uart.c b/src/lib/drivers/pn532_uart.c index d22aae5..89562bb 100644 --- a/src/lib/drivers/pn532_uart.c +++ b/src/lib/drivers/pn532_uart.c @@ -169,7 +169,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd) // We have a connection pnd = malloc(sizeof(nfc_device_t)); strncpy(pnd->acName, pndd->acDevice, DEVICE_NAME_LENGTH - 1); - pnd->acName[DEVICE_NAME_LENGTH] = '\0'; + pnd->acName[DEVICE_NAME_LENGTH - 1] = '\0'; pnd->nc = NC_PN532; pnd->nds = (nfc_device_spec_t)sp;