author | Lars Hjemli <hjemli@gmail.com> | 2006-12-28 00:54:43 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-28 00:54:43 (UTC) |
commit | 27cd3b2a700e1cc46cd0393ddea48c07b62ee3a6 (patch) (side-by-side diff) | |
tree | 041158893604fa4127bc0df31a2c22f8d48b852f | |
parent | c43f1246cb759eb811ab0ebef0613b86dda99581 (diff) | |
download | cgit-27cd3b2a700e1cc46cd0393ddea48c07b62ee3a6.zip cgit-27cd3b2a700e1cc46cd0393ddea48c07b62ee3a6.tar.gz cgit-27cd3b2a700e1cc46cd0393ddea48c07b62ee3a6.tar.bz2 |
Test for NULL-pointers in html_txt() and friends
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | html.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -16,143 +16,142 @@ char *fmt(const char *format, ...) va_list args; bufidx++; bufidx &= 7; va_start(args, format); len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); va_end(args); if (len>sizeof(buf[bufidx])) die("[html.c] string truncated: %s", format); return buf[bufidx]; } 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){ + while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='&') { *t = '\0'; html(txt); *t = c; 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 && len--){ + while(t && *t && len--){ int c = *t; if (c=='<' || c=='>' || c=='&') { *t = '\0'; html(txt); *t = c; 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 (len<0) html("..."); } void html_attr(char *txt) { char *t = txt; - while(*t){ + while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='\'') { *t = '\0'; html(txt); *t = c; if (c=='>') html(">"); else if (c=='<') html("<"); else if (c=='\'') html(""e;"); txt = t+1; } t++; } if (t!=txt) html(txt); } void html_link_open(char *url, char *title, char *class) { html("<a href='"); html_attr(url); if (title) { html("' title='"); html_attr(title); } if (class) { html("' class='"); html_attr(class); } html("'>"); } void html_link_close(void) { html("</a>"); } void html_fileperm(unsigned short mode) { htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); } void html_filemode(unsigned short mode) { if (S_ISDIR(mode)) html("d"); else if (S_ISLNK(mode)) html("l"); else html("-"); html_fileperm(mode >> 6); html_fileperm(mode >> 3); html_fileperm(mode); } - |