libftdi Archives

Subject: [2/5]new-baudrate-code/origin:ftdi_eeprom/main.c: Malloc the eeprom Buffer with the size exported by the API

From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 8 Sep 2011 10:11:14 +0200
-- 
Uwe Bonnes                bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From 8fcf39d1d2e70e96e07781170b90589fee73508b Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 8 Sep 2011 09:32:16 +0200
Subject: ftdi_eeprom/main.c: Malloc the eeprom Buffer with the size exported by 
the API

---
 ftdi_eeprom/main.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index df7c877..931045f 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
     int _read = 0, _erase = 0, _flash = 0;
 
     int my_eeprom_size = 0;
-    unsigned char eeprom_buf[FTDI_MAX_EEPROM_SIZE];
+    unsigned char *eeprom_buf = NULL;
     char *filename;
     int size_check;
     int i, argc_filename;
@@ -264,9 +264,16 @@ int main(int argc, char *argv[])
         printf("serial = \"%s\"\n", eeprom->serial);
         */
 
+        eeprom_buf = malloc(my_eeprom_size);
+        ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
+
+        if (eeprom_buf == NULL)
+        {
+            fprintf(stderr, "Malloc failed, aborting\n");
+            goto cleanup;
+        }
         if (filename != NULL && strlen(filename) > 0)
         {
-            ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
 
             FILE *fp = fopen (filename, "wb");
             fwrite (eeprom_buf, 1, my_eeprom_size, fp);
@@ -368,6 +375,8 @@ int main(int argc, char *argv[])
     }
 
 cleanup:
+    if (eeprom_buf)
+        free(eeprom_buf);
     if (_read > 0 || _erase > 0 || _flash > 0)
     {
         printf("FTDI close: %d\n", ftdi_usb_close(ftdi));
-- 
1.7.3.4


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • [2/5]new-baudrate-code/origin:ftdi_eeprom/main.c: Malloc the eeprom Buffer with the size exported by the API, Uwe Bonnes <=