From a98b4f488e25657e3d20fd64680d36b09650f812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20Hern=C3=A0ndez=20Juan?= <shernand@iri.upc.edu> Date: Tue, 2 Jul 2013 07:00:00 +0000 Subject: [PATCH] Solved a problem with the input arguments. The input arguments are checked before being used to avoid errors. --- src/examples/test_ftdi.cpp | 43 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/examples/test_ftdi.cpp b/src/examples/test_ftdi.cpp index c3e26de..e8a46cf 100644 --- a/src/examples/test_ftdi.cpp +++ b/src/examples/test_ftdi.cpp @@ -61,29 +61,32 @@ int main(int argc, char *argv[]) ftdi_config.latency_timer = 16; try{ - std::cout << (*ftdi_server) << std::endl; - if(ftdi_server->get_num_devices()>0) - { - while(ftdi_device==NULL && count>0) + std::cout << (*ftdi_server) << std::endl; + if(ftdi_server->get_num_devices()>0) { - try{ - ftdi_device=ftdi_server->get_device(ftdi_server->get_serial_number(atoi(argv[1]))); - }catch(CException &e){ - std::cout << e.what() << std::endl; - count--; + while(ftdi_device==NULL && count>0) + { + try{ + if(argc>=2) + ftdi_device=ftdi_server->get_device(ftdi_server->get_serial_number(atoi(argv[1]))); + else + ftdi_device=ftdi_server->get_device(ftdi_server->get_serial_number(0)); + }catch(CException &e){ + std::cout << e.what() << std::endl; + count--; + } + } + if(count==0) + std::cout << "Device not available" << std::endl; + else + { + ftdi_device->config(&ftdi_config); + std::cout << (*ftdi_device) << std::endl; + ftdi_device->close(); } } - if(count==0) - std::cout << "Device not available" << std::endl; - else - { - ftdi_device->config(&ftdi_config); - std::cout << (*ftdi_device) << std::endl; - ftdi_device->close(); - } - } - if(ftdi_device!=NULL) - delete ftdi_device; + if(ftdi_device!=NULL) + delete ftdi_device; }catch(CException &e){ std::cout << e.what() << std::endl; } -- GitLab