From cc8b6e96c31fbb4a927d85f201c1c5586d79a7d7 Mon Sep 17 00:00:00 2001 From: Tattersalt-Kanzaki Date: Tue, 7 Jan 2025 23:02:52 +0300 Subject: [PATCH] got rid of expressions that are always true --- lib/xlsxio_read.c | 18 ++++++++---------- lib/xlsxio_write.c | 42 ++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/xlsxio_read.c b/lib/xlsxio_read.c index e02de1c..e6342a9 100644 --- a/lib/xlsxio_read.c +++ b/lib/xlsxio_read.c @@ -764,17 +764,15 @@ void main_sheet_list_expat_callback_element_start (void* callbackdata, const XML const XML_Char* sheetname; //const XML_Char* relid = get_expat_attr_by_name(atts, X("r:id")); if ((sheetname = get_expat_attr_by_name(atts, X("name"))) != NULL) { - if (data->callback) { - if ((*data->callback)(sheetname, data->callbackdata) != 0) { - XML_StopParser(data->xmlparser, XML_FALSE); - return; - } + if ((*data->callback)(sheetname, data->callbackdata) != 0) { + XML_StopParser(data->xmlparser, XML_FALSE); + return; + } /* - } else { - //for non-calback method suspend here - XML_StopParser(data->xmlparser, XML_TRUE); + } else { + //for non-calback method suspend here + XML_StopParser(data->xmlparser, XML_TRUE); */ - } } } } @@ -1142,7 +1140,7 @@ void data_sheet_expat_callback_find_cell_start (void* callbackdata, const XML_Ch if ((data->flags & XLSXIOREAD_SKIP_EXTRA_CELLS) && data->cols > 0 && cellmax > data->cols) cellmax = data->cols; while (data->colnr < cellmax) { - if (data->colnr > 0 && data->sheet_cell_callback) { + if (data->sheet_cell_callback) { if ((*data->sheet_cell_callback)(data->rownr, data->colnr + 1, NULL, data->callbackdata)) { XML_StopParser(data->xmlparser, XML_FALSE); return; diff --git a/lib/xlsxio_write.c b/lib/xlsxio_write.c index f065855..f9c466b 100644 --- a/lib/xlsxio_write.c +++ b/lib/xlsxio_write.c @@ -915,30 +915,28 @@ void write_cell_data (xlsxiowriter handle, const char* rowattr, const char* pref if (suffix) append_data(&handle->buf, &handle->buflen, suffix); //collect cell information - if (!handle->sheetopen) { - if (!*handle->pcurrentcolumn) { - //create new column information structure - struct column_info_struct* colinfo; - if ((colinfo = (struct column_info_struct*)malloc(sizeof(struct column_info_struct))) != NULL) { - colinfo->width = 0; - colinfo->maxwidth = 0; - colinfo->next = NULL; - *handle->pcurrentcolumn = colinfo; - } - } - //keep track of biggest column width - if (data) { - //only count first line in multiline data - char* p = strchr(data, '\n'); - if (p) - datalen = p - data; - //remember this length if it is the longest one so far - if (datalen > 0 && datalen > (*handle->pcurrentcolumn)->maxwidth) - (*handle->pcurrentcolumn)->maxwidth = datalen; + if (!*handle->pcurrentcolumn) { + //create new column information structure + struct column_info_struct* colinfo; + if ((colinfo = (struct column_info_struct*)malloc(sizeof(struct column_info_struct))) != NULL) { + colinfo->width = 0; + colinfo->maxwidth = 0; + colinfo->next = NULL; + *handle->pcurrentcolumn = colinfo; } - //prepare for the next column - handle->pcurrentcolumn = &(*handle->pcurrentcolumn)->next; } + //keep track of biggest column width + if (data) { + //only count first line in multiline data + char* p = strchr(data, '\n'); + if (p) + datalen = p - data; + //remember this length if it is the longest one so far + if (datalen > 0 && datalen > (*handle->pcurrentcolumn)->maxwidth) + (*handle->pcurrentcolumn)->maxwidth = datalen; + } + //prepare for the next column + handle->pcurrentcolumn = &(*handle->pcurrentcolumn)->next; } #if !defined(NO_ROW_NUMBERS) && !defined(NO_COLUMN_NUMBERS) free(cellcoord);