From d9c62a32df99cc602b95bff5eebae430c0de2e02 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 2 Jan 2015 20:29:31 +0100 Subject: sfeed: fix incorrect strlcpy, style and strict check for buf --- sfeed.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sfeed.c b/sfeed.c index f911aa1..ab7a5b8 100644 --- a/sfeed.c +++ b/sfeed.c @@ -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); -- cgit v1.2.3