geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit aef0076447d9ca07b4e758287f611e6cbbda224e
parent 387ac8be93c952305d9ef77e95ca21852cd47f4a
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 14 Jun 2017 22:54:50 +0200

Save geomyidae from invalid gph files.

Diffstat:
ind.c | 58++++++++++++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/ind.c b/ind.c @@ -177,41 +177,43 @@ addelem(Elems *e, char *s) Elems * getadv(char *str) { - char *b, *e; + char *b, *e, *o; Elems *ret; ret = xcalloc(1, sizeof(Elems)); - if(*str != '[') { - b = str; - if(*str == 't') - b++; - addelem(ret, "i"); - addelem(ret, b); - addelem(ret, "Err"); - addelem(ret, "server"); - addelem(ret, "port"); - - return ret; - } + if (str[0] == '[') { + o = xstrdup(str); + b = o + 1; + while ((e = strchr(b, '|')) != nil) { + *e = '\0'; + e++; + addelem(ret, b); + b = e; + } - b = str + 1; - while((e = strchr(b, '|')) != nil) { - *e = '\0'; - e++; - addelem(ret, b); - b = e; - } + e = strchr(b, ']'); + if (e != nil) { + *e = '\0'; + addelem(ret, b); + } + free(o); + if (ret->e != nil && ret->num == 5) + return ret; - e = strchr(b, ']'); - if(e != nil) { - *e = '\0'; - addelem(ret, b); - } - if(ret->e == nil) { - free(ret); - return nil; + /* Invalid entry: Give back the whole line. */ + freeelem(ret); + ret = xcalloc(1, sizeof(Elems)); } + b = str; + if(*str == 't') + b++; + addelem(ret, "i"); + addelem(ret, b); + addelem(ret, "Err"); + addelem(ret, "server"); + addelem(ret, "port"); + return ret; }