Re: [PATCH] libftdi: pass eeprom strings as const
Hi Dan, You wrote on Tue, Jan 07, 2020 at 11:18:30AM -0500: > These strings are not modified and it doesn't make sense that they ever > would be. Setting these as const ensures that they will not be modified > and allows const strings to be passed in without special manipulation. > > Specifically a call like the following will fail to compile: > ftdi_eeprom_set_strings(&ftdi, "foo", "bar", "abc123"); > > The error will look something like this: > error: ISO C++ forbids converting a string constant to ‘char*’ > [-Werror=write-strings] thanks for the patch, applied! Given recent juggling on my side with Rust, C++ and C, I inspected the ABI of the library if anything changes at all as a precaution -> all stable. Nice tool to check for ABI changes in libs: https://lvc.github.io/abi-compliance-checker/ For testing the tool I changed the "serial" parameter bogusly from "const char *" to "char" and the tool caught it. Sweet! Cheers, Thomas -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to libftdi+unsubscr...@developer.intra2net.com
Re: [PATCH] libftdi: pass eeprom strings as const
On Tue, Jan 7, 2020 at 5:18 PM Dan Dedrick wrote: > > These strings are not modified and it doesn't make sense that they ever > would be. Setting these as const ensures that they will not be modified > and allows const strings to be passed in without special manipulation. > > Specifically a call like the following will fail to compile: > ftdi_eeprom_set_strings(&ftdi, "foo", "bar", "abc123"); > > The error will look something like this: > error: ISO C++ forbids converting a string constant to ‘char*’ > [-Werror=write-strings] > --- > src/ftdi.c | 4 ++-- > src/ftdi.h | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/src/ftdi.c b/src/ftdi.c > index 988a9f1..9495fb5 100644 > --- a/src/ftdi.c > +++ b/src/ftdi.c > @@ -2724,8 +2724,8 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, > char * manufacturer, > return 0; > } > > -int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, char * manufacturer, > -char * product, char * serial) > +int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, const char * > manufacturer, > +const char * product, const char * serial) > { > struct ftdi_eeprom *eeprom; > > diff --git a/src/ftdi.h b/src/ftdi.h > index 8fcf719..7addeb9 100644 > --- a/src/ftdi.h > +++ b/src/ftdi.h > @@ -544,8 +544,8 @@ extern "C" > char *manufacturer, int mnf_len, > char *product, int prod_len, > char *serial, int serial_len); > -int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, char * > manufacturer, > -char * product, char * serial); > +int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, const char * > manufacturer, > +const char * product, const char * serial); > > int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product); > int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int > product, > -- > 2.7.4 Good catch. Regards, Yegor -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to libftdi+unsubscr...@developer.intra2net.com
[PATCH] libftdi: pass eeprom strings as const
These strings are not modified and it doesn't make sense that they ever would be. Setting these as const ensures that they will not be modified and allows const strings to be passed in without special manipulation. Specifically a call like the following will fail to compile: ftdi_eeprom_set_strings(&ftdi, "foo", "bar", "abc123"); The error will look something like this: error: ISO C++ forbids converting a string constant to ‘char*’ [-Werror=write-strings] --- src/ftdi.c | 4 ++-- src/ftdi.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index 988a9f1..9495fb5 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -2724,8 +2724,8 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer, return 0; } -int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, char * manufacturer, -char * product, char * serial) +int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, const char * manufacturer, +const char * product, const char * serial) { struct ftdi_eeprom *eeprom; diff --git a/src/ftdi.h b/src/ftdi.h index 8fcf719..7addeb9 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -544,8 +544,8 @@ extern "C" char *manufacturer, int mnf_len, char *product, int prod_len, char *serial, int serial_len); -int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, char * manufacturer, -char * product, char * serial); +int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, const char * manufacturer, +const char * product, const char * serial); int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product); int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product, -- 2.7.4 -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to libftdi+unsubscr...@developer.intra2net.com