issue#137

This commit is contained in:
Tattersalt-Kanzaki 2025-01-07 04:48:21 +03:00
parent de9d53a842
commit 917c1bf2b6
4 changed files with 17 additions and 6 deletions

View File

@ -1264,10 +1264,12 @@ void data_sheet_expat_callback_value_data (void* callbackdata, const XML_Char* b
{
struct data_sheet_callback_data* data = (struct data_sheet_callback_data*)callbackdata;
if (data->cell_string_type != none) {
if ((data->celldata = XML_Char_realloc(data->celldata, data->celldatalen + buflen + 1)) == NULL) {
XML_Char *temp = XML_Char_realloc(data->celldata, data->celldatalen + buflen + 1);
if (temp == NULL) {
//memory allocation error
data->celldatalen = 0;
} else {
data->celldata = temp;
//add new data to value buffer
XML_Char_poscpy(data->celldata, data->celldatalen, buf, buflen);
data->celldatalen += buflen;

View File

@ -195,10 +195,12 @@ void shared_strings_callback_find_shared_string_end (void* callbackdata, const X
void shared_strings_callback_string_data (void* callbackdata, const XML_Char* buf, int buflen)
{
struct shared_strings_callback_data* data = (struct shared_strings_callback_data*)callbackdata;
if ((data->text = XML_Char_realloc(data->text, data->textlen + buflen)) == NULL) {
XML_Char *temp = XML_Char_realloc(data->text, data->textlen + buflen);
if (temp == NULL) {
//memory allocation error
data->textlen = 0;
} else {
data->text = temp;
XML_Char_poscpy(data->text, data->textlen, buf, buflen);
data->textlen += buflen;
}

View File

@ -398,9 +398,12 @@ char* str_replace (char** s, size_t pos, size_t len, char* replacement)
pos = totallen;
if (pos + len > totallen)
len = totallen - pos;
if (replacementlen > len)
if ((*s = (char*)realloc(*s, totallen - len + replacementlen + 1)) == NULL)
if (replacementlen > len) {
char *temp = (char*)realloc(*s, totallen - len + replacementlen + 1);
if (temp == NULL)
return NULL;
*s = temp;
}
memmove(*s + pos + replacementlen, *s + pos + len, totallen - pos - len + 1);
memcpy(*s + pos, replacement, replacementlen);
return *s;
@ -484,8 +487,10 @@ int append_data (char** pdata, size_t* pdatalen, const char* format, ...)
va_end(args);
if (len < 0)
return -1;
if ((*pdata = (char*)realloc(*pdata, *pdatalen + len + 1)) == NULL)
char *temp = (char*)realloc(*pdata, *pdatalen + len + 1);
if (temp == NULL)
return -1;
*pdata = temp;
va_start(args, format);
vsnprintf(*pdata + *pdatalen, len + 1, format, args);
va_end(args);

View File

@ -36,8 +36,10 @@ THE SOFTWARE.
int append_buffer_data (char** pdata, size_t* pdatalen, const char* bufferdata, size_t bufferdatalen)
{
//allocate larger data buffer, abort in case of memory allocation error
if ((*pdata = (char*)realloc(*pdata, *pdatalen + bufferdatalen + 1)) == NULL)
char *temp = (char*)realloc(*pdata, *pdatalen + bufferdatalen + 1);
if (temp == NULL)
return 1;
*pdata = temp;
//append new data and adjust length
memcpy(*pdata + *pdatalen, bufferdata, bufferdatalen);
*pdatalen += bufferdatalen;