From 7b917f9a8b55e26ee9a4ed9b2dfc2b9618196142 Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Mon, 4 Mar 2013 01:26:23 -0500 Subject: [PATCH] Windows: Clean up all compiler warnings and link warnings - Fixed the suppression of the auto-fixup for linking against MS built libs - Fixed all the formatting warnings by shifting to inttypes.h specifiers - shifted to %lu for DWORD printf --- CMakeLists.txt | 6 +++--- examples/nfc-poll.c | 3 ++- examples/nfc-relay.c | 3 ++- libnfc/buses/uart_win32.c | 5 +++-- libnfc/chips/pn53x.c | 7 ++++--- libnfc/drivers/acr122_pcsc.c | 2 +- libnfc/drivers/acr122_usb.c | 2 +- libnfc/drivers/acr122s.c | 2 +- libnfc/drivers/arygon.c | 4 ++-- libnfc/drivers/pn532_uart.c | 2 +- libnfc/drivers/pn53x_usb.c | 2 +- libnfc/target-subr.c | 7 ++++--- utils/nfc-relay-picc.c | 5 +++-- 13 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba2dc3b..4e203c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,9 +79,9 @@ ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t) IF(MINGW) # force MinGW-w64 in 32bit mode SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}") - SET(CMAKE_MODULE_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") - SET(CMAKE_SHARED_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") - SET(CMAKE_EXE_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}") + SET(CMAKE_MODULE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") + SET(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") + SET(CMAKE_EXE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}") SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}") ENDIF(MINGW) diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index 40cd87d..6ef1805 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -38,6 +38,7 @@ #endif // HAVE_CONFIG_H #include +#include #include #include #include @@ -128,7 +129,7 @@ main(int argc, const char *argv[]) } printf("NFC reader: %s opened\n", nfc_device_get_name(pnd)); - printf("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations); + printf("NFC device will poll during %ld ms (%u pollings of %lu ms for %" PRIdPTR " modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations); if ((res = nfc_initiator_poll_target(pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) { nfc_perror(pnd, "nfc_initiator_poll_target"); nfc_close(pnd); diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 8dbdcd9..9d1061c 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -37,6 +37,7 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include #include #include #include @@ -119,7 +120,7 @@ main(int argc, char *argv[]) size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT); if (szFound < 2) { - ERR("%zd device found but two opened devices are needed to relay NFC.", szFound); + ERR("%" PRIdPTR " device found but two opened devices are needed to relay NFC.", szFound); nfc_exit(context); exit(EXIT_FAILURE); } diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index f14e28d..0c675ad 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -24,6 +24,7 @@ * @brief Windows UART driver */ +#include #include "log.h" #define LOG_GROUP NFC_LOG_GROUP_COM @@ -164,7 +165,7 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new timeout settings."); return NFC_EIO; } - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %u ms", timeout_ms); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %lu ms", timeout_ms); // TODO Enhance the reception method // - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello() @@ -179,7 +180,7 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i if (!res) { DWORD err = GetLastError(); - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "ReadFile error: %u", err); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "ReadFile error: %lu", err); return NFC_EIO; } else if (dwBytesReceived == 0) { return NFC_ETIMEOUT; diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 96c4bda..a4a5153 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -28,6 +28,7 @@ # include "config.h" #endif // HAVE_CONFIG_H +#include #include #include #include @@ -1354,7 +1355,7 @@ pn53x_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, c const size_t szRxLen = (size_t)res - 1; if (pbtRx != NULL) { if (szRxLen > szRx) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %zuo available(s), %zuo needed", szRx, szRxLen); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %" PRIuPTR " available(s), %" PRIuPTR " needed", szRx, szRxLen); return NFC_EOVFLOW; } // Copy the received bytes @@ -1629,7 +1630,7 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb } if (pbtRx != NULL) { if ((szRxLen + sz) > szRx) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %zuo available(s), %zuo needed", szRx, szRxLen + sz); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Buffer size is too short: %" PRIuPTR " available(s), %" PRIuPTR " needed", szRx, szRxLen + sz); return NFC_EOVFLOW; } // Copy the received bytes @@ -2711,7 +2712,7 @@ pn53x_build_frame(uint8_t *pbtFrame, size_t *pszFrame, const uint8_t *pbtData, c (*pszFrame) = szData + PN53x_EXTENDED_FRAME__OVERHEAD; } else { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "We can't send more than %d bytes in a raw (requested: %zd)", PN53x_EXTENDED_FRAME__DATA_MAX_LEN, szData); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "We can't send more than %d bytes in a raw (requested: %" PRIdPTR ")", PN53x_EXTENDED_FRAME__DATA_MAX_LEN, szData); return NFC_ECHIP; } return NFC_SUCCESS; diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index b8337ea..4341aad 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -255,7 +255,7 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring) if (strlen(ndd.pcsc_device_name) < 5) { // We can assume it's a reader ID as pcsc_name always ends with "NN NN" // Device was not specified, only ID, retrieve it size_t index; - if (sscanf(ndd.pcsc_device_name, "%4lu", &index) != 1) + if (sscanf(ndd.pcsc_device_name, "%4" SCNuPTR, &index) != 1) return NULL; nfc_connstring *ncs = malloc(sizeof(nfc_connstring) * (index + 1)); if (!ncs) { diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index d2c439f..93e65f3 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -718,7 +718,7 @@ read: len -= 4; // We skip 2 bytes for PN532 direction byte (D5) and command byte (CMD+1), then 2 bytes for APDU status (90 00). if (len > szDataLen) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); pnd->last_error = NFC_EOVFLOW; return pnd->last_error; } diff --git a/libnfc/drivers/acr122s.c b/libnfc/drivers/acr122s.c index c84a8da..3daf30b 100644 --- a/libnfc/drivers/acr122s.c +++ b/libnfc/drivers/acr122s.c @@ -684,7 +684,7 @@ acr122s_receive(nfc_device *pnd, uint8_t *buf, size_t buf_len, int timeout) size_t data_len = FRAME_SIZE(tmp) - 17; if (data_len > buf_len) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Receive buffer too small. (buf_len: %zu, data_len: %zu)", buf_len, data_len); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Receive buffer too small. (buf_len: %" PRIuPTR ", data_len: %" PRIuPTR ")", buf_len, data_len); pnd->last_error = NFC_EIO; return pnd->last_error; } diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 315fc0b..729b0b8 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -330,7 +330,7 @@ arygon_tama_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i size_t szFrame = 0; if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) { // ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?) - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ARYGON device does not support more than %d bytes as payload (requested: %" PRIdPTR ")", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData); pnd->last_error = NFC_EDEVNOTSUPP; return pnd->last_error; } @@ -438,7 +438,7 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i } if (len > szDataLen) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); pnd->last_error = NFC_EIO; return pnd->last_error; } diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 4ae4380..6816558 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -424,7 +424,7 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in } if (len > szDataLen) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); pnd->last_error = NFC_EIO; goto error; } diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 1d229c5..edc9eee 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -588,7 +588,7 @@ read: } if (len > szDataLen) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len); pnd->last_error = NFC_EIO; return pnd->last_error; } diff --git a/libnfc/target-subr.c b/libnfc/target-subr.c index b46d6bc..9429839 100644 --- a/libnfc/target-subr.c +++ b/libnfc/target-subr.c @@ -23,6 +23,7 @@ * @file target-subr.c * @brief Target-related subroutines. (ie. determine target type, print target, etc.) */ +#include #include #include "target-subr.h" @@ -248,9 +249,9 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info *pna uint8_t TC = pnai->abtAts[offset]; offset++; if (TC & 0x1) { - off += snprintf(dst + off, size - off, "* Node ADdress supported\n"); + off += snprintf(dst + off, size - off, "* Node Address supported\n"); } else { - off += snprintf(dst + off, size - off, "* Node ADdress not supported\n"); + off += snprintf(dst + off, size - off, "* Node Address not supported\n"); } if (TC & 0x2) { off += snprintf(dst + off, size - off, "* Card IDentifier supported\n"); @@ -271,7 +272,7 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info *pna offset++; if (L != (pnai->szAtsLen - offset)) { off += snprintf(dst + off, size - off, " * Warning: Type Identification Coding length (%i)", L); - off += snprintf(dst + off, size - off, " not matching Tk length (%zi)\n", (pnai->szAtsLen - offset)); + off += snprintf(dst + off, size - off, " not matching Tk length (%" PRIdPTR ")\n", (pnai->szAtsLen - offset)); } if ((pnai->szAtsLen - offset - 2) > 0) { // Omit 2 CRC bytes uint8_t CTC = pnai->abtAts[offset]; diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index ed180ca..dd92607 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -42,6 +42,7 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include #include #include #include @@ -100,7 +101,7 @@ static int print_hex_fd4(const uint8_t *pbtData, const size_t szBytes, const cha if (szBytes > MAX_FRAME_LEN) { return -1; } - if (fprintf(fd4, "#%s %04zx: ", pchPrefix, szBytes) < 0) { + if (fprintf(fd4, "#%s %04" PRIxPTR ": ", pchPrefix, szBytes) < 0) { return -1; } @@ -225,7 +226,7 @@ main(int argc, char *argv[]) } } else { if (szFound < 2) { - ERR("%zd device found but two opened devices are needed to relay NFC.", szFound); + ERR("%" PRIdPTR " device found but two opened devices are needed to relay NFC.", szFound); nfc_exit(context); exit(EXIT_FAILURE); }