summaryrefslogtreecommitdiff
path: root/src/inlines.c
AgeCommit message (Collapse)Author
2020-05-13Don't call memcpy with NULL as 1st parameter.John MacFarlane
This is illegal according to the C standard, sec. 7.1.4. "If an argument to a function has an invalid value (such as a value outside the domain of the function, or a pointer outside the address space of the program, or a null pointer, or a pointer to non-modifiable storage when the corresponding parameter is not const-qualified) or a type (after promotion) not expected by a function with variable number of arguments, the behavior is undefined." 7.24.1(2): "Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero […] pointer arguments on such a call shall still have valid values, as described in 7.1.4." See https://www.imperialviolet.org/2016/06/26/nonnull.html
2020-05-13Add NOLINTNEXTLINE to avoid a useless linter error.John MacFarlane
2020-01-23Rearrange struct cmark_nodeNick Wellnhofer
Introduce multi-purpose data/len members in struct cmark_node. This is mainly used to store literal text for inlines, code and HTML blocks. Move the content strbuf for blocks from cmark_node to cmark_parser. When finalizing nodes that allow inlines (paragraphs and headings), detach the strbuf and store the block content in the node's data/len members. Free the block content after processing inlines. Reduces size of struct cmark_node by 8 bytes.
2020-01-23Use C string instead of chunk for literal textNick Wellnhofer
Use zero-terminated C strings and a separate length field instead of cmark_chunks. Literal inline text will now be copied from the parent block's content buffer, slowing the benchmark down by 10-15%. The node struct never references memory of other nodes now, fixing #309. Node accessors don't have to check for delayed creation of C strings, so parsing and iterating all literals using the public API should actually be faster than before.
2020-01-23Use C string instead of chunk for link URL and titleNick Wellnhofer
Use zero-terminated C strings instead of cmark_chunks without storing the length. This introduces a few additional strlen computations, but overhead should be low. Allows to reduce size of struct cmark_node later.
2019-11-11Cleaner approach to max digits for numeric entities.John MacFarlane
This modifies unescaping in houdini_html_u.c rather than the entity handling in inlines.c. Unlike the other, this approach works also in e.g. link titles.
2019-11-11Fix entity parser (and api test) to respect length limit on numeric entities.John MacFarlane
2019-11-11Code reformatJohn MacFarlane
2019-11-11Don't allow link destinations with unbalanced unescaped parentheses.John MacFarlane
See commonmark/commonmark.js#177.
2019-04-04Update code span normalization...John MacFarlane
to conform with spec change.
2019-04-03Allow empty `<>` link destination in reference link.John MacFarlane
2019-03-26Fix #289.John MacFarlane
A link destination can't start with `<` unless it is an angle-bracket link that also ends with `>`. (If your URL really starts with `<`, URL-escape it.)
2019-03-23Update spec; allow internal delimiter runs to match if...John MacFarlane
both have lengths that are multiples of 3. See commonmark/commonmark#528.
2019-03-19Update spec. Fix `[link](<foo\>)`.John MacFarlane
2019-03-17Avoid gcc warning for uninitialized variable.John MacFarlane
2018-11-13copy line/col info straight from opener/closerAshe Connor
We can't rely on anything in `subj` since it's been modified while parsing the subject and could represent line info from a future line. This is simple and works.
2018-09-09Check for whitespace before reference title.John MacFarlane
Closes #263.
2018-08-26Simplify code normalization, in line with spec change.John MacFarlane
2018-08-25Code span spec changes.John MacFarlane
These affect both parsing and writing commonmark.
2018-03-25Allow spaces in link destination delimited with pointy brackets.John MacFarlane
To conform to recent spec change.
2017-11-05Merge pull request #217 from github/upstream/limit-nested-parensJohn MacFarlane
> 32 nested balanced parens in a link is bananas
2017-11-02Merge branch 'master' into upstream/inline-sourceposAshe Connor
2017-09-14blocks: Fix quadratic behavior in `finalize`Vicent Marti
2017-08-10Skip sourcepos tracking if disabledYuki Izumi
2017-08-10Fix inlines spanning newlines, text in non-paraYuki Izumi
2017-08-09--smart: open quote can never occur right after `]` or `)`.John MacFarlane
Closes #227.
2017-08-09Add sourcepos info for inlinesYuki Izumi
2017-08-03Reformat source code with 'make format'Nguyễn Thái Ngọc Duy
2017-07-17Fix URL scanner.Yuki Izumi
2017-07-12> 32 nested balanced parens in a link is bananasYuki Izumi
2017-07-06Avoid memcpy'ing NULL pointersPhil Turnbull
A UBSAN warning can be triggered because the link title is an empty string: src/inlines.c:113:20: runtime error: null pointer passed as argument 2, which is declared to never be null which can be triggered by: ``` [f]:_ [f] ``` The length of the memcpy is zero so the NULL pointer is not dereferenced but it is still undefined behaviour.
2017-06-29DeMorgan simplification of some tests in emphasis parser.John MacFarlane
This also brings the code into closer alignment with the wording of the spec. See jgm/CommonMark#467.
2017-06-02Properly handle backslashes in link destinations.John MacFarlane
Only ascii punctuation characters are escapable, per the spec. Closes #192.
2017-04-03Fixed code for freeing delimiter stack.John MacFarlane
Note, however, that this may not be needed at all: the old code would have gone into an infinite loop if the delimiter stack were not already freed. If we can prove that the delimiter stack is empty at this point, we could remove this; on the other hand, it may not hurt to keep it here defensively. Closes #189.
2017-01-08Update emphasis parsing for spec change.John MacFarlane
Strong now goes inside Emph rather than the reverse, when both scopes are possible. The code is much simpler. This also avoids a spec inconsistency that cmark had previously: `***hi***` became Strong (Emph "hi")) but `***hi****` became Emph (Strong "hi")) "*"
2017-01-05Automatic code reformatting.John MacFarlane
2017-01-05Added a test for NULL when freeing subj->last_delim.John MacFarlane
Noticed the need for this through fuzzing.
2017-01-05Cleaned up setting of lower bounds for openers.John MacFarlane
We now use a much smaller array.
2017-01-03Fixes #178, quadratic parsing bug.John MacFarlane
2017-01-03Slight improvement of clarity of logic in emph matching.John MacFarlane
2017-01-03Revert "More sourcepos! (#169)"John MacFarlane
This reverts commit 9e643720ec903f3b448bd2589a0c02c2514805ae.
2017-01-03Revert "Change types for source map offsets (#174)"John MacFarlane
This reverts commit 4fbe344df43ed7f60a3d3a53981088334cb709fc.
2017-01-03Fix "multiple of 3" determination in emph/strong parsing.John MacFarlane
We need to store the length of the original delimiter run, instead of using the length of the remaining delimiters after some have been subtracted. Test case: a***b* c* Thanks to Raph Levin for reporting.
2016-12-30Change types for source map offsets (#174)Nick Wellnhofer
* Improve strbuf guarantees Introduce BUFSIZE_MAX macro and make sure that the strbuf implementation can handle strings up to this size. * Abort early if document size exceeds internal limit * Change types for source map offsets Switch to size_t for the public API, making the public headers C89-compatible again. Switch to bufsize_t internally, reducing memory usage and improving performance on 32-bit platforms. * Make parser return NULL on internal index overflow Make S_parser_feed set an error and ignore subsequent chunks if the total input document size exceeds an internal limit. Make cmark_parser_finish return NULL if an error was encountered. Add public API functions to retrieve error code and error message. strbuf overflow in renderers and OOM in parser or renderers still cause an abort.
2016-12-20More sourcepos! (#169)Mathieu Duponchelle
* open_new_blocks: always create child before advancing offset * Source map * Extent's typology * In-depth python bindings
2016-12-01Allow balanced nested parens in link destinations (#166)Yuki Izumi
2016-11-26Allocate enough bytes for backticks array.John MacFarlane
2016-11-26Inlines: Ensure that the delimiter stack is freed in subject.John MacFarlane
2016-11-26Fixed pathological cases with backtick code spans:John MacFarlane
- Removed recursion in scan_to_closing_backticks - Added an array of pointers to potential backtick closers to subject - This array is used to avoid traversing the subject again when we've already seen all the potential backtick closers. - Added a max bound of 1000 for backtick code span delimiters. - This helps with pathological cases like: x x ` x `` x ``` x ```` ... Thanks to Martin Mitáš for identifying the problem and for discussion of solutions.
2016-10-30Modified print_delimiters (commented out) so it compiles again.John MacFarlane