From 9cb9e0e6da5cb5abdb1303f8dd5e33c73a1f5c58 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 5 Apr 2013 14:38:03 +0200 Subject: [PATCH] Fix cppcheck warning: The scope of the variable X can be reduced. --- examples/pn53x-diagnose.c | 2 +- examples/pn53x-tamashell.c | 2 +- libnfc/drivers/acr122_pcsc.c | 3 +-- test/test_dep_active.c | 2 +- test/test_device_modes_as_dep.c | 3 +-- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index afa15ec..008b39b 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -60,7 +60,6 @@ main(int argc, const char *argv[]) nfc_device *pnd = NULL; const char *acLibnfcVersion; bool result; - int res = 0; uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); @@ -92,6 +91,7 @@ main(int argc, const char *argv[]) } for (i = 0; i < szFound; i++) { + int res = 0; pnd = nfc_open(context, connstrings[i]); if (pnd == NULL) { diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index b60ec5a..3223b21 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -120,10 +120,10 @@ int main(int argc, const char *argv[]) exit(EXIT_FAILURE); } - char *cmd; const char *prompt = "> "; while (1) { int offset = 0; + char *cmd; #if defined(HAVE_READLINE) if (input == NULL) { // means we use stdin cmd = readline(prompt); diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index 3a0f889..ef1b0b0 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -154,7 +154,6 @@ acr122_pcsc_scan(const nfc_context *context, nfc_connstring connstrings[], const char acDeviceNames[256 + 64 * PCSC_MAX_DEVICES]; size_t szDeviceNamesLen = sizeof(acDeviceNames); SCARDCONTEXT *pscc; - bool bSupported; int i; // Clear the reader list @@ -172,7 +171,7 @@ acr122_pcsc_scan(const nfc_context *context, nfc_connstring connstrings[], const size_t device_found = 0; while ((acDeviceNames[szPos] != '\0') && (device_found < connstrings_len)) { - bSupported = false; + bool bSupported = false; for (i = 0; supported_devices[i] && !bSupported; i++) { int l = strlen(supported_devices[i]); bSupported = 0 == strncmp(supported_devices[i], acDeviceNames + szPos, l); diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 0ea9c1d..ff87f6e 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -151,7 +151,6 @@ initiator_thread(void *arg) void test_dep_active(void) { - int res; nfc_baud_rate nbrs[3] = { NBR_106, NBR_212, NBR_424}; CutTestContext *test_context = cut_get_current_test_context(); @@ -167,6 +166,7 @@ test_dep_active(void) for (int i = 0; i < 3; i++) { initiator_data.nbr = nbrs[i]; + int res; if ((res = pthread_create(&(threads[TARGET]), NULL, target_thread, &target_data))) cut_fail("pthread_create() returned %d", res); diff --git a/test/test_device_modes_as_dep.c b/test/test_device_modes_as_dep.c index 39a9764..48ee9b9 100644 --- a/test/test_device_modes_as_dep.c +++ b/test/test_device_modes_as_dep.c @@ -177,8 +177,6 @@ initiator_thread(void *arg) void test_dep_states(void) { - int res; - CutTestContext *test_context = cut_get_current_test_context(); struct thread_data target_data = { .device = first_device, @@ -191,6 +189,7 @@ test_dep_states(void) }; for (int i = 0; i < 2; i++) { + int res; if ((res = pthread_create(&(threads[1]), NULL, target_thread, &target_data))) cut_fail("pthread_create() returned %d", res);