X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/568d8d3fd3f5a3b4207887215c8adcbac2bb9552..fe1bb0e765883fa4149fba12daee81b6ae070de3:/parsing.c 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;