Skip to content

Improve the C-ness of the code #7

@ndmitchell

Description

@ndmitchell

@thoughtpolice in https://www.reddit.com/r/haskell/comments/5i2mg1/new_xml_parser_hexml/db5os2h/ says:

Also, IMO, the C library could be improved a bit, too e.g. it should probably be namespaced so everything is under hexml_, and I'm not sure about the usage of document_parse taking an int vs a size_t which is what strlen returns (int and size_t do not have the same sign, making such loose conversions extremely dangerous).

The only reason document_parse handles int is so you can pass -1 so it will call strlen itself, but frankly, I'd just suggest making a totally separate function to do this. Or just not have this 'feature' at all -- users should always be expected to reasonably know the size of the fragment they pass to document_parse, right? It also assumes that the input to the string is actually null terminated, but if it isn't, strlen is going to do something very bad (by returning some massive integer). Assuming the input is hostile means I'm always going to assume someone, somehow, snuck in a non-null terminated string...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions