X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/0a799424f682071da9f5b632d1394308e9255bb5..7ea35f9f8ecf61ab42be9947aae1176ab6e089bd:/parsing.c?ds=sidebyside diff --git a/parsing.c b/parsing.c index c9e4350..1b2a551 100644 --- a/parsing.c +++ b/parsing.c @@ -56,6 +56,8 @@ char *substr(const char *head, const char *tail) { char *buf; + if (tail < head) + return xstrdup(""); buf = xmalloc(tail - head + 1); strncpy(buf, head, tail - head); buf[tail - head] = '\0'; @@ -103,7 +105,10 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc) { char *tmp; - if (!txt || !*txt || !src_enc || !dst_enc) + if (!txt) + return NULL; + + if (!*txt || !src_enc || !dst_enc) return *txt; /* no encoding needed if src_enc equals dst_enc */ @@ -122,7 +127,7 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc) struct commitinfo *cgit_parse_commit(struct commit *commit) { struct commitinfo *ret; - char *p = commit->buffer, *t = commit->buffer; + char *p = commit->buffer, *t; ret = xmalloc(sizeof(*ret)); ret->commit = commit;