return true;
}
+#define MAX_TLV_VALUE_LEN 256
+
+/**
+ * Copy a TLV string.
+ */
+static int tlv_copy_string(char *buf, const char *string, int *new_tlv_len)
+{
+ if (!string) {
+ printf("ERROR: NULL string passed in\n");
+ return -1;
+ }
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+ strncpy(buf, string, MAX_TLV_VALUE_LEN);
+#pragma GCC diagnostic pop
+ *new_tlv_len = min_t(size_t, MAX_TLV_VALUE_LEN, strlen(string));
+
+ return 0;
+}
+
/**
* tlvinfo_add_tlv
*
* This function adds a TLV to the EEPROM, converting the value (a string) to
* the format in which it will be stored in the EEPROM.
*/
-#define MAX_TLV_VALUE_LEN 256
bool tlvinfo_add_tlv(u8 *eeprom, int tcode, char *strval)
{
struct tlvinfo_header *eeprom_hdr = to_header(eeprom);
case TLV_CODE_VENDOR_NAME:
case TLV_CODE_DIAG_VERSION:
case TLV_CODE_SERVICE_TAG:
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wstringop-truncation"
- strncpy(data, strval, MAX_TLV_VALUE_LEN);
-#pragma GCC diagnostic pop
- new_tlv_len = min_t(size_t, MAX_TLV_VALUE_LEN, strlen(strval));
+ tlv_copy_string(data, strval, &new_tlv_len);
break;
case TLV_CODE_DEVICE_VERSION:
value = simple_strtoul(strval, NULL, 0);