diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-01-02 20:29:31 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-01-02 20:29:31 +0100 |
commit | d9c62a32df99cc602b95bff5eebae430c0de2e02 (patch) | |
tree | 5cf58e11833b45270051e64919760e1b9a6b0196 | |
parent | 1f7beb9181acf0f18d37449bb209e92a12572015 (diff) |
sfeed: fix incorrect strlcpy, style and strict check for buf
-rw-r--r-- | sfeed.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -309,7 +309,8 @@ gettimetz(const char *s, char *buf, size_t bufsiz) unsigned int i; char c; - buf[0] = '\0'; + if(buf && bufsiz > 0) + buf[0] = '\0'; if(bufsiz < sizeof(tzname) + STRSIZ(" -00:00")) return 0; for(; *p && isspace((int)*p); p++); /* skip whitespace */ @@ -319,7 +320,7 @@ gettimetz(const char *s, char *buf, size_t bufsiz) /* TODO: cleanup / simplify */ if(isalpha((int)*p)) { if(*p == 'Z' || *p == 'z') { - strlcpy(buf, "GMT+00:00", sizeof(buf)); + strlcpy(buf, "GMT+00:00", bufsiz); return 0; } else { for(i = 0, t = &tzname[0]; i < (sizeof(tzname) - 1) && @@ -333,8 +334,10 @@ gettimetz(const char *s, char *buf, size_t bufsiz) strlcpy(buf, tzname, bufsiz); return 0; } - if((sscanf(p, "%c%02d:%02d", &c, &tzhour, &tzmin)) > 0); - else if(sscanf(p, "%c%02d%02d", &c, &tzhour, &tzmin) > 0); + if((sscanf(p, "%c%02d:%02d", &c, &tzhour, &tzmin)) > 0) + ; + else if(sscanf(p, "%c%02d%02d", &c, &tzhour, &tzmin) > 0) + ; else if(sscanf(p, "%c%d", &c, &tzhour) > 0) tzmin = 0; snprintf(buf, bufsiz, "%s%c%02d%02d", tzname, c, tzhour, tzmin); |