From 601105ef7984665fc6448f24cdcae638a8f77155 Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Thu, 5 Jan 2012 17:03:38 +0000 Subject: [PATCH] fix bad cast done in last revision. --- examples/nfc-dep-target.c | 4 +++- examples/nfc-emulate-tag.c | 4 +++- libnfc/nfc-emulation.c | 2 +- test/test_dep_active.c | 6 +++--- test/test_dep_passive.c | 22 +++++++++++++--------- utils/nfc-relay-picc.c | 4 +++- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 77a912f..82ce9f1 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -62,6 +62,7 @@ int main (int argc, const char *argv[]) { uint8_t abtRx[MAX_FRAME_LEN]; + int res = 0; size_t szRx = sizeof(abtRx); size_t szDeviceFound; uint8_t abtTx[] = "Hello Mars!"; @@ -125,10 +126,11 @@ main (int argc, const char *argv[]) } printf("Initiator request received. Waiting for data...\n"); - if (((int) (szRx = (size_t) nfc_target_receive_bytes (pnd, abtRx, 0))) < 0) { + if ((res = nfc_target_receive_bytes (pnd, abtRx, 0)) < 0) { nfc_perror(pnd, "nfc_target_receive_bytes"); goto error; } + szRx = (size_t) res; abtRx[szRx] = '\0'; printf ("Received: %s\n", abtRx); diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 3604ab7..c83eecf 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -137,6 +137,7 @@ bool nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt) { size_t szTx; + int res = 0; uint8_t abtTx[MAX_FRAME_LEN]; bool loop = true; @@ -158,10 +159,11 @@ nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt) nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false); init_mfc_auth = false; } - if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) { + if ((res = nfc_target_receive_bytes(pnd, abtRx, 0)) < 0) { nfc_perror (pnd, "nfc_target_receive_bytes"); return false; } + szRx = (size_t) res; } } return true; diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index 21db471..a5eabd7 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -47,7 +47,7 @@ nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator) } } if (res >= 0) { - if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) { + if ((res = nfc_target_receive_bytes(pnd, abtRx, 0)) < 0) { return -1; } } diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 71235aa..e77fce8 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -88,9 +88,9 @@ target_thread (void *arg) cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } - szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); - cut_assert_operator_int (szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); - + res = nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) res; const uint8_t abtAttRx[] = "Hello DEP target!"; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index a6af765..0b709da 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -87,9 +87,10 @@ target_thread (void *arg) if (res < 0) { thread_res = -1; return (void*) thread_res; } // First pass - szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); - cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); - + res = nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) res; + const uint8_t abtAttRx[] = "Hello DEP target!"; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } @@ -100,8 +101,9 @@ target_thread (void *arg) if (res <= 0) { thread_res = -1; return (void*) thread_res; } // Second pass - szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); - cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + res = nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) res; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } @@ -111,8 +113,9 @@ target_thread (void *arg) if (res <= 0) { thread_res = -1; return (void*) thread_res; } // Third pass - szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); - cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + res = nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) res; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } @@ -122,8 +125,9 @@ target_thread (void *arg) if (res <= 0) { thread_res = -1; return (void*) thread_res; } // Fourth pass - szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500); - cut_assert_operator_int ((int)szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + res = nfc_target_receive_bytes (device, abtRx, 500); + cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); + szRx = (size_t) res; cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res <= 0) { thread_res = -1; return (void*) thread_res; } diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index d80e7ed..002cf61 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -368,9 +368,10 @@ main (int argc, char *argv[]) while (!quitting) { bool ret; + int res = 0; if (!initiator_only_mode) { // Receive external reader command through target - if ((int) ((szCapduLen = (size_t) nfc_target_receive_bytes(pndTarget, abtCapdu, 0))) < 0) { + if ((res = nfc_target_receive_bytes(pndTarget, abtCapdu, 0)) < 0) { nfc_perror (pndTarget, "nfc_target_receive_bytes"); if (!target_only_mode) { nfc_disconnect (pndInitiator); @@ -378,6 +379,7 @@ main (int argc, char *argv[]) nfc_disconnect (pndTarget); exit(EXIT_FAILURE); } + szCapduLen = (size_t) res; if (target_only_mode) { if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing C-APDU to FD4\n");