aboutsummaryrefslogtreecommitdiffstats
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/html.c b/html.c
index e7e6e07..7f81965 100644
--- a/html.c
+++ b/html.c
@@ -124,29 +124,20 @@ void html_vtxtf(const char *format, va_list ap)
124 124
125void html_txt(const char *txt) 125void html_txt(const char *txt)
126{ 126{
127 const char *t = txt; 127 if (txt)
128 while (t && *t) { 128 html_ntxt(txt, strlen(txt));
129 int c = *t;
130 if (c == '<' || c == '>' || c == '&') {
131 html_raw(txt, t - txt);
132 if (c == '>')
133 html("&gt;");
134 else if (c == '<')
135 html("&lt;");
136 else if (c == '&')
137 html("&amp;");
138 txt = t + 1;
139 }
140 t++;
141 }
142 if (t != txt)
143 html(txt);
144} 129}
145 130
146void html_ntxt(int len, const char *txt) 131ssize_t html_ntxt(const char *txt, size_t len)
147{ 132{
148 const char *t = txt; 133 const char *t = txt;
149 while (t && *t && len--) { 134 ssize_t slen;
135
136 if (len > SSIZE_MAX)
137 return -1;
138
139 slen = (ssize_t) len;
140 while (t && *t && slen--) {
150 int c = *t; 141 int c = *t;
151 if (c == '<' || c == '>' || c == '&') { 142 if (c == '<' || c == '>' || c == '&') {
152 html_raw(txt, t - txt); 143 html_raw(txt, t - txt);
@@ -162,8 +153,7 @@ void html_ntxt(int len, const char *txt)
162 } 153 }
163 if (t != txt) 154 if (t != txt)
164 html_raw(txt, t - txt); 155 html_raw(txt, t - txt);
165 if (len < 0) 156 return slen;
166 html("...");
167} 157}
168 158
169void html_attrf(const char *fmt, ...) 159void html_attrf(const char *fmt, ...)