Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtsanders committed Mar 20, 2020
1 parent e3d3dc2 commit f03b05e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
0.2.25

2020-03-19 Brecht Sanders https://github.com/brechtsanders/
2020-03-20 Brecht Sanders https://github.com/brechtsanders/

* fixed memory leaks in xlsxioread_sheet_next_cell_int/xlsxioread_sheet_next_cell_float/xlsxioread_sheet_next_cell_datetime (issue #54)
* added xml:space="preserve" to text cells to preserve spacing (issue #16)
* ran valgrind tests on xlsxio_xlsx2csv and xlsxio_csv2xlsx
* fixed memory leak in write_cell_data() in xlsxio_write.c (result of get_A1col was not freed)
* rewrote get_A1col() in in xlsxio_write.c to avoid issues on platforms where multiple calls to va_start()/va_end() don't work

0.2.24

Expand Down
2 changes: 1 addition & 1 deletion build/libxlsxio_write_shared.depend
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# depslib dependency file v1.0
1584631289 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_write.c
1584724326 source:\\server\users\brecht\sources\cpp\xlsxio\lib\xlsxio_write.c
"xlsxio_write.h"
"xlsxio_version.h"
<stdlib.h>
Expand Down
27 changes: 24 additions & 3 deletions lib/xlsxio_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ int append_data (char** pdata, size_t* pdatalen, const char* format, ...)
}

#ifndef NO_COLUMN_NUMBERS
/*
//insert formatted data into a null-terminated buffer at the specified position and update the length counter
int insert_data (char** pdata, size_t* pdatalen, size_t pos, const char* format, ...)
{
Expand All @@ -508,7 +509,7 @@ int insert_data (char** pdata, size_t* pdatalen, size_t pos, const char* format,
else
(*pdata)[pos + len] = 0;
va_start(args, format);
vsnprintf(*pdata + pos, len, format, args);
len = vsnprintf(*pdata + pos, len, format, args);
va_end(args);
*pdatalen += len;
return len;
Expand All @@ -521,7 +522,25 @@ char* get_A1col (uint64_t col)
if (col > 0) {
do {
col--;
insert_data(&result, &resultlen, 0, "%c", 'A' + col % 26);
insert_data(&result, &resultlen, 0, "%c", 'A' + (col % 26));
col = col / 26;
} while (col > 0);
}
return result;
}
*/

char* get_A1col (uint64_t col)
{
char* result = NULL;
size_t resultlen = 0;
//allocate 19 bytes as the maximum value for 64-bit devided by 26 has 18 digits
if (col > 0 && (result = (char*)malloc(19)) != NULL) {
result[0] = 0;
do {
col--;
memmove(result + 1, result, ++resultlen);
result[0] = 'A' + (col % 26);
col = col / 26;
} while (col > 0);
}
Expand Down Expand Up @@ -579,7 +598,6 @@ struct xlsxio_write_struct {
#define ROWNRPARAM(handle) , handle->rownr
#ifndef NO_COLUMN_NUMBERS
#define COLNRTAG " r=\"%s%" PRIu64 "\""
#define COLNRPARAM(handle) , get_A1col(handle->colnr), handle->rownr
#endif
#endif

Expand Down Expand Up @@ -861,6 +879,9 @@ void write_cell_data (xlsxiowriter handle, const char* rowattr, const char* pref
//determine cell coordinate
#if !defined(NO_ROW_NUMBERS) && !defined(NO_COLUMN_NUMBERS)
cellcoord = get_A1col(++handle->colnr);
#define COLNRPARAM(handle) , cellcoord, handle->rownr
#else
#define COLNRPARAM(handle)
#endif
//add cell data
if (handle->sheetopen) {
Expand Down

0 comments on commit f03b05e

Please sign in to comment.