From: Yegor Yefremov <yegorsli...@googlemail.com> Handle user_data the same way as the main EEPROM buffer. Copy buffer instead of assigning a pointer in ftdi_set_eeprom_user_data(). This is required because if used from Python, the input buf is not available as soon as the ftdi_set_eeprom_user_data() exits. --- src/ftdi.c | 9 +++++++-- src/ftdi_i.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c index 0a7fb27..eca122c 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -3475,7 +3475,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) } /* Arbitrary user data */ - if (eeprom->user_data && eeprom->user_data_size >= 0) + if (eeprom->user_data_size > 0) { if (eeprom->user_data_addr < free_start) fprintf(stderr,"Warning, user data starts inside the generated data!\n"); @@ -4440,8 +4440,13 @@ int ftdi_set_eeprom_user_data(struct ftdi_context *ftdi, const char * buf, int s if (!ftdi || !(ftdi->eeprom) || !buf) ftdi_error_return(-1, "No appropriate structure"); + // Only copy up to FTDI_MAX_EEPROM_SIZE bytes + if (size > FTDI_MAX_EEPROM_SIZE) + size = FTDI_MAX_EEPROM_SIZE; + ftdi->eeprom->user_data_size = size; - ftdi->eeprom->user_data = buf; + memcpy(ftdi->eeprom->user_data, buf, size); + return 0; } diff --git a/src/ftdi_i.h b/src/ftdi_i.h index 5d04120..accae1c 100644 --- a/src/ftdi_i.h +++ b/src/ftdi_i.h @@ -129,7 +129,7 @@ struct ftdi_eeprom /** user data **/ int user_data_addr; int user_data_size; - const char *user_data; + unsigned char user_data[FTDI_MAX_EEPROM_SIZE]; /** eeprom size in bytes. This doesn't get stored in the eeprom but is the only way to pass it to ftdi_eeprom_build. */ -- 2.34.1 -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to libftdi+unsubscr...@developer.intra2net.com