I found number of issues from sxmlc. I've included a patch that should fix them all (but feel free to verify the fixes manually).
Here's a (hopefully complete) list of the issues fixed:
- wrong error return code for number of functions (NULL vs -1).
- off by one bug when checking 'i_tag' in XML_unregister_user_tag.
- XML_unregister_user_tag always removed the last tag, not the 'i_tag' index one.
- off by one bug when checking 'i_node' in XMLDoc_remove_node.
- generic: fixed assuption that size reducing realloc cannot fail (it can fail on some architectures).
- number of functions left the elements in inconsistent state in error code paths. now if error occcurs no changes will be made.
- avoid allocating 0 bytes of memory (malloc for 0 bytes might return NULL, realloc of 0 bytes has undefined return value).
- XML_parse_1string could modify 'str' permanently in some error code paths.
- initialize newly realloc()ated array entry in XML_parse_1string to avoid referencing to uninitialized pointers.
- make sure to zero xmlattr->name and xmlattr->value in XMLDoc_remove_node to avoid double free later.
- doc->filename ended up unterminated with long 'filename' parameter in XMLDoc_parse_file_DOM_text_as_nodes
- realloc with 0 sz and valid mem ptr didn't increase nb_free counter
- freadBOM didn't check for ftell/fread errors
- added missing sx_strdup failure check in XMLSearch_search_set_text
- fixed a bogus statement
&(*xpath[sx_strlen(*xpath)]); in _get_XPath
Oh man... I should really thank you twice: first for the amount of time you spent analyzing the code, second for giving me the corrections!
Shame on me for those silly bugs in core functions. Thanks for the lesson, a true hacker indeed! :)
Needless to say I have integrated your corrections, though not word-by-word sometimes (like
if (pt != NULL)instead ofif (pt), or two missing{in the modifiedfreadBOM()).So I have created v4.2.0 from your corrections, feel free to diff it to your update, in case I double-missed something...
Now, may I ask you if you checked all that because you're actually using sxmlc or just out of intellectual interest (or both ;))? Do you use any lint-like tool or just your brain (or both ;))? Sorry for being so curious, I want to improve as well :)
sxmlc will likely be used in a project by a friend, mainly because it's not multimegabyte behemoth like some other xml libs, and is very light on dependecies.
I used manual checking method: code review. I've been writing C for 25+ years now so I have fairly good understanding.
Oh just to add, there's nothing wrong with lint tools, those are good as well, but obviously can't replace humans. They're nice in spotting typos and mistakes like that. They're less likely to spot logical flaws.