Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/sxmlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1877,11 +1877,20 @@ int XMLDoc_parse_file_SAX(const SXML_CHAR* filename, const SAX_Callbacks* sax, v

int XMLDoc_parse_buffer_SAX_len(const SXML_CHAR* buffer, int buffer_len, const SXML_CHAR* name, const SAX_Callbacks* sax, void* user)
{
DataSourceBuffer dsb = { buffer, buffer_len, 0 };
#ifdef _MSC_VER
SAX_Data sd = {0};
#else
#ifdef __CODEGEARC__
SAX_Data sd;
DataSourceBuffer dsb;
dsb.buf = buffer;
dsb.buf_len = buffer_len;
dsb.cur_pos = 0;
#else
DataSourceBuffer dsb = { buffer, buffer_len, 0 };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this does not compile with RAD Studio? Which C version does the compiler use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact this code isn't working with Embarcadero RAD studio XE7. It's the reason for the #ifdef CODEGEARC instead of #ifdef _MSC_VER, as for the other ifdefs. On the other hands I compiled this code without issue with Visual Studio 2019, Code::Blocks and xCode :-)


#ifdef _MSC_VER
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is specific to MS Visual Studio. Does it complain about a structure not being initialized?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I added this ifdef (as well as some similar in several other locations) is that I have a huge list of warnings claimed by Visual Studio otherwise, saying more or less that this value may be used without be initialized. It was somewhat annoying for me, because this drowned out other important warnings I should not miss.

SAX_Data sd = {0};
#else
SAX_Data sd;
#endif
#endif

if (sax == NULL || buffer == NULL)
Expand Down Expand Up @@ -2178,7 +2187,7 @@ int read_line_alloc(void* in, DataSourceType in_type, SXML_CHAR** line, int* sz_
} else
*line = pt;
}
if (sz_line && n < *sz_line)
if (line && sz_line && n < *sz_line)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which version of sxmlc are you using? In the latest (4.5.1), line cannot be NULL here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, and I understand that you're puzzled. I added that because Visual Studio was claiming a Buffer Overrun on this line. All in all this resolved nothing, I just forgotten to remove it, you can thus get rid of that. The warning I receive is the following:
Warning C6386 Buffer overrun while writing to '*line': the writable size is 'sz_linesizeof(SXML_CHAR)' bytes, but '2' bytes might be written. ...\sxmlc.c 2191

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE I'm compiling in 64 bit, it's may be the reason why I receive many more warnings than other users ;-)

(*line)[n] = NULC; /* If we reached the 'to' character and we want to strip it, 'n' hasn't changed and 'line[n]' (which is 'to') will be replaced by '\0' */
if (ch == to) {
ret = n;
Expand Down Expand Up @@ -2627,6 +2636,4 @@ int regstrcmp(SXML_CHAR* str, SXML_CHAR* pattern)
break;
}
}

return FALSE;
}