We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 21c11a2 commit eab4b65Copy full SHA for eab4b65
3 files changed
src/workbook.c
@@ -737,8 +737,10 @@ _store_defined_name(lxw_workbook *self, const char *name,
737
/* Remove any worksheet quoting. */
738
if (worksheet_name[0] == '\'')
739
worksheet_name++;
740
- if (worksheet_name[strlen(worksheet_name) - 1] == '\'')
+ if (strlen(worksheet_name) > 0
741
+ && worksheet_name[strlen(worksheet_name) - 1] == '\'') {
742
worksheet_name[strlen(worksheet_name) - 1] = '\0';
743
+ }
744
745
/* Search for worksheet name to get the equivalent worksheet index. */
746
STAILQ_FOREACH(sheet, self->sheets, list_pointers) {
@@ -976,8 +978,9 @@ _populate_range_dimensions(lxw_workbook *self, lxw_series_range *range)
976
978
977
979
if (sheetname[0] == '\'')
980
sheetname++;
- if (sheetname[strlen(sheetname) - 1] == '\'')
981
+ if (strlen(sheetname) > 0 && sheetname[strlen(sheetname) - 1] == '\'') {
982
sheetname[strlen(sheetname) - 1] = '\0';
983
984
985
/* Check that the sheetname exists. */
986
if (!workbook_get_worksheet_by_name(self, sheetname)) {
src/worksheet.c
@@ -8127,16 +8127,25 @@ _store_array_formula(lxw_worksheet *self,
8127
8128
/* Copy and trip leading "{=" from formula. */
8129
if (formula[0] == '{')
8130
- if (formula[1] == '=')
+ if (strlen(formula) >= 2 && formula[1] == '=')
8131
formula_copy = lxw_strdup(formula + 2);
8132
else
8133
formula_copy = lxw_strdup(formula + 1);
8134
8135
formula_copy = lxw_strdup_formula(formula);
8136
8137
/* Strip trailing "}" from formula. */
8138
- if (formula_copy[strlen(formula_copy) - 1] == '}')
+ if (strlen(formula_copy) > 0
8139
+ && formula_copy[strlen(formula_copy) - 1] == '}') {
8140
formula_copy[strlen(formula_copy) - 1] = '\0';
8141
8142
+
8143
+ /* Check for empty formula that started as {=}. */
8144
+ if (lxw_str_is_empty(formula_copy)) {
8145
+ free(formula_copy);
8146
+ free(range);
8147
+ return LXW_ERROR_PARAMETER_IS_EMPTY;
8148
8149
8150
/* Create a new array formula cell object. */
8151
cell = _new_array_formula_cell(first_row, first_col,
test/unit/worksheet/test_worksheet_range_returns.c
@@ -105,6 +105,19 @@ CTEST(worksheet, bound_checks01) {
105
err = worksheet_set_column(worksheet, MAX_COL, 6, 17, NULL);
106
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
107
108
+ /* Tests array formula strings. */
109
+ err = worksheet_write_array_formula(worksheet, 0, 0, 0, 0, "{", NULL);
110
+ ASSERT_EQUAL(LXW_ERROR_PARAMETER_IS_EMPTY, err);
111
112
+ err = worksheet_write_array_formula(worksheet, 0, 0, 0, 0, "}", NULL);
113
114
115
+ err = worksheet_write_array_formula(worksheet, 0, 0, 0, 0, "{}", NULL);
116
117
118
+ err = worksheet_write_array_formula(worksheet, 0, 0, 0, 0, "{=}", NULL);
119
120
121
lxw_worksheet_assemble_xml_file(worksheet);
122
123
lxw_worksheet_free(worksheet);
0 commit comments