diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2015-06-07 13:24:26 -0700 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2015-06-07 13:24:26 -0700 | 
| commit | 802270f434a72935ba75c725b3cadcae4f478735 (patch) | |
| tree | b045b8831ac4c691ce90c41efa8e04b5330918da /src/html.c | |
| parent | 3adc586d9d7539e4d33f737110ffd4e236379099 (diff) | |
| parent | fdfa1e4bedf95691389efb9991ac8a6a4599c158 (diff) | |
Merge pull request #56 from nwellnhof/bufsize_t
Safer handling of string buffer sizes and indices
Diffstat (limited to 'src/html.c')
| -rw-r--r-- | src/html.c | 25 | 
1 files changed, 7 insertions, 18 deletions
| @@ -11,20 +11,9 @@  // Functions to convert cmark_nodes to HTML strings. -static void escape_html(cmark_strbuf *dest, const unsigned char *source, int length) +static void escape_html(cmark_strbuf *dest, const unsigned char *source, bufsize_t length)  { -	if (length < 0) -		length = strlen((char *)source); - -	houdini_escape_html0(dest, source, (size_t)length, 0); -} - -static void escape_href(cmark_strbuf *dest, const unsigned char *source, int length) -{ -	if (length < 0) -		length = strlen((char *)source); - -	houdini_escape_href(dest, source, (size_t)length); +	houdini_escape_html0(dest, source, length, 0);  }  static inline void cr(cmark_strbuf *html) @@ -165,7 +154,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,  			S_render_sourcepos(node, html, options);  			cmark_strbuf_puts(html, "><code>");  		} else { -			int first_tag = 0; +			bufsize_t first_tag = 0;  			while (first_tag < node->as.code.info.len &&  			       node->as.code.info.data[first_tag] != ' ') {  				first_tag += 1; @@ -261,8 +250,8 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,  	case CMARK_NODE_LINK:  		if (entering) {  			cmark_strbuf_puts(html, "<a href=\""); -			escape_href(html, node->as.link.url.data, -			            node->as.link.url.len); +			houdini_escape_href(html, node->as.link.url.data, +	                                    node->as.link.url.len);  			if (node->as.link.title.len) {  				cmark_strbuf_puts(html, "\" title=\""); @@ -279,8 +268,8 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,  	case CMARK_NODE_IMAGE:  		if (entering) {  			cmark_strbuf_puts(html, "<img src=\""); -			escape_href(html, node->as.link.url.data, -			            node->as.link.url.len); +			houdini_escape_href(html, node->as.link.url.data, +		                            node->as.link.url.len);  			cmark_strbuf_puts(html, "\" alt=\"");  			state->plain = node; | 
