author | Hiroki Hattori <seagull.kamome@gmail.com> | 2008-02-23 17:57:34 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-02-23 19:11:59 (UTC) |
commit | eacde43d7184452e1fdc90b982b531f1f5239923 (patch) (side-by-side diff) | |
tree | d2cc9342fd96a7c5a7287b708d958631a446d274 /html.c | |
parent | b74cc91574a9284d2f6446fd2ef3df6298ed6992 (diff) | |
download | cgit-eacde43d7184452e1fdc90b982b531f1f5239923.zip cgit-eacde43d7184452e1fdc90b982b531f1f5239923.tar.gz cgit-eacde43d7184452e1fdc90b982b531f1f5239923.tar.bz2 |
Fix segfault
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | html.c | 20 |
1 files changed, 5 insertions, 15 deletions
@@ -27,103 +27,93 @@ char *fmt(const char *format, ...) } void html(const char *txt) { write(htmlfd, txt, strlen(txt)); } void htmlf(const char *format, ...) { static char buf[65536]; va_list args; va_start(args, format); vsnprintf(buf, sizeof(buf), format, args); va_end(args); html(buf); } void html_txt(char *txt) { char *t = txt; while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='&') { - *t = '\0'; - html(txt); - *t = c; + write(htmlfd, txt, t - txt); if (c=='>') html(">"); else if (c=='<') html("<"); else if (c=='&') html("&"); txt = t+1; } t++; } if (t!=txt) html(txt); } void html_ntxt(int len, char *txt) { char *t = txt; while(t && *t && len--){ int c = *t; if (c=='<' || c=='>' || c=='&') { - *t = '\0'; - html(txt); - *t = c; + write(htmlfd, txt, t - txt); if (c=='>') html(">"); else if (c=='<') html("<"); else if (c=='&') html("&"); txt = t+1; } t++; } - if (t!=txt) { - char c = *t; - *t = '\0'; - html(txt); - *t = c; - } + if (t!=txt) + write(htmlfd, txt, t - txt); if (len<0) html("..."); } void html_attr(char *txt) { char *t = txt; while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='\'') { - *t = '\0'; - html(txt); - *t = c; + write(htmlfd, txt, t - txt); if (c=='>') html(">"); else if (c=='<') html("<"); else if (c=='\'') html(""e;"); txt = t+1; } t++; } if (t!=txt) html(txt); } void html_hidden(char *name, char *value) { html("<input type='hidden' name='"); html_attr(name); html("' value='"); html_attr(value); html("'/>"); } void html_option(char *value, char *text, char *selected_value) |