diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-04-25 11:55:14 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-04-25 15:28:29 +0300 |
commit | eabf5f3583f10bd0f52c15ecedefec88efd2c670 (patch) | |
tree | 51aa4b0dbe29df91e71c2e0f9955b957c7219f6f /build | |
parent | f9a95483bb09672c9efdeba82c015c12dd6c7291 (diff) | |
download | librpm-tizen-eabf5f3583f10bd0f52c15ecedefec88efd2c670.tar.gz librpm-tizen-eabf5f3583f10bd0f52c15ecedefec88efd2c670.tar.bz2 librpm-tizen-eabf5f3583f10bd0f52c15ecedefec88efd2c670.zip |
Single point of exit for dateToTimet(), avoid alloca()
Diffstat (limited to 'build')
-rw-r--r-- | build/parseChangelog.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/build/parseChangelog.c b/build/parseChangelog.c index cbb28e943..7cf1e9a5f 100644 --- a/build/parseChangelog.c +++ b/build/parseChangelog.c @@ -33,68 +33,72 @@ void addChangelogEntry(Header h, time_t time, const char *name, const char *text */ static int dateToTimet(const char * datestr, time_t * secs) { + int rc = -1; /* assume failure */ struct tm time; const char * const * idx; - char * p, * pe, * q; + char *p, *pe, *q, *date; - char * date = strcpy(alloca(strlen(datestr) + 1), datestr); -static const char * const days[] = + static const char * const days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL }; -static const char * const months[] = + static const char * const months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL }; -static const char const lengths[] = + static const char const lengths[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; memset(&time, 0, sizeof(time)); + date = xstrdup(datestr); pe = date; /* day of week */ p = pe; SKIPSPACE(p); - if (*p == '\0') return -1; + if (*p == '\0') goto exit; pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0'; for (idx = days; *idx && strcmp(*idx, p); idx++) {}; - if (*idx == NULL) return -1; + if (*idx == NULL) goto exit; /* month */ p = pe; SKIPSPACE(p); - if (*p == '\0') return -1; + if (*p == '\0') goto exit; pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0'; for (idx = months; *idx && strcmp(*idx, p); idx++) {}; - if (*idx == NULL) return -1; + if (*idx == NULL) goto exit; time.tm_mon = idx - months; /* day */ p = pe; SKIPSPACE(p); - if (*p == '\0') return -1; + if (*p == '\0') goto exit; pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0'; /* make this noon so the day is always right (as we make this UTC) */ time.tm_hour = 12; time.tm_mday = strtol(p, &q, 10); - if (!(q && *q == '\0')) return -1; - if (time.tm_mday < 0 || time.tm_mday > lengths[time.tm_mon]) return -1; + if (!(q && *q == '\0')) goto exit; + if (time.tm_mday < 0 || time.tm_mday > lengths[time.tm_mon]) goto exit; /* year */ p = pe; SKIPSPACE(p); - if (*p == '\0') return -1; + if (*p == '\0') goto exit; pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0'; time.tm_year = strtol(p, &q, 10); - if (!(q && *q == '\0')) return -1; - if (time.tm_year < 1990 || time.tm_year >= 3000) return -1; + if (!(q && *q == '\0')) goto exit; + if (time.tm_year < 1990 || time.tm_year >= 3000) goto exit; time.tm_year -= 1900; *secs = mktime(&time); - if (*secs == -1) return -1; + if (*secs == -1) goto exit; /* adjust to GMT */ *secs += timezone; + rc = 0; - return 0; +exit: + free(date); + return rc; } /** |