libxlsxwriter/src/workbook.c in fast_excel-0.2.3 vs libxlsxwriter/src/workbook.c in fast_excel-0.2.5

- old
+ new

@@ -1,11 +1,11 @@ /***************************************************************************** * workbook - A library for creating Excel XLSX workbook files. * * Used in conjunction with the libxlsxwriter library. * - * Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt. + * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt. * */ #include "xlsxwriter/xmlwriter.h" #include "xlsxwriter/workbook.h" @@ -402,27 +402,28 @@ lxw_hash_table *num_formats = lxw_hash_new(128, 0, 1); lxw_hash_element *hash_element; lxw_hash_element *used_format_element; uint16_t index = 0xA4; uint16_t num_format_count = 0; - char *num_format; uint16_t *num_format_index; LXW_FOREACH_ORDERED(used_format_element, self->used_xf_formats) { lxw_format *format = (lxw_format *) used_format_element->value; /* Format already has a number format index. */ if (format->num_format_index) continue; /* Check if there is a user defined number format string. */ - num_format = format->num_format; + if (*format->num_format) { + char num_format[LXW_FORMAT_FIELD_LEN] = { 0 }; + lxw_snprintf(num_format, LXW_FORMAT_FIELD_LEN, "%s", + format->num_format); - if (*num_format) { /* Look up the num_format in the hash table. */ hash_element = lxw_hash_key_exists(num_formats, num_format, - strlen(num_format)); + LXW_FORMAT_FIELD_LEN); if (hash_element) { /* Num_Format has already been used. */ format->num_format_index = *(uint16_t *) hash_element->value; } @@ -430,10 +431,11 @@ /* This is a new num_format. */ num_format_index = calloc(1, sizeof(uint16_t)); *num_format_index = index; format->num_format_index = index; lxw_insert_hash_element(num_formats, num_format, - num_format_index, strlen(num_format)); + num_format_index, + LXW_FORMAT_FIELD_LEN); index++; num_format_count++; } } }