diff options
author | Yunchih Chen <yunchih.cat@gmail.com> | 2018-03-21 23:15:38 +0800 |
---|---|---|
committer | Yunchih Chen <yunchih.cat@gmail.com> | 2018-03-21 23:15:38 +0800 |
commit | f9bdba7abd71be51933ce1a414215595120c69a2 (patch) | |
tree | 9db97b00de0c16c330e31648a5ca0fef8ade2451 | |
parent | c3570154ea3a4210253cba4febc857ebb5d5c5e7 (diff) | |
download | nfcollect-f9bdba7abd71be51933ce1a414215595120c69a2.tar.gz nfcollect-f9bdba7abd71be51933ce1a414215595120c69a2.tar.zst nfcollect-f9bdba7abd71be51933ce1a414215595120c69a2.zip |
Fix indexing bug
-rw-r--r-- | bin/nfcollect.c | 6 | ||||
-rw-r--r-- | bin/nfextract.c | 2 | ||||
-rw-r--r-- | lib/common.c | 2 |
3 files changed, 6 insertions, 4 deletions
diff --git a/bin/nfcollect.c b/bin/nfcollect.c index 4168fd7..e168595 100644 --- a/bin/nfcollect.c +++ b/bin/nfcollect.c @@ -161,7 +161,8 @@ int main(int argc, char *argv[]) { info(PACKAGE ": requested to truncate (overwrite) trunks in %s", storage_dir); } else { - cur_trunk = NEXT(calculate_starting_trunk(storage_dir), trunk_cnt); + int calculated_trunk = calculate_starting_trunk(storage_dir); + cur_trunk = calculated_trunk < 0 ? 0: NEXT(calculated_trunk, trunk_cnt); const char *fn = nfl_get_filename(storage_dir, cur_trunk); info(PACKAGE ": will start writing to trunk %s and onward", fn); free((char *)fn); @@ -185,13 +186,14 @@ int main(int argc, char *argv[]) { /* * Need to find a trunk to start with after a restart * We choose the one with newest modification time. + * If no existing trunk is found, returns -1 */ static uint32_t calculate_starting_trunk(const char *storage_dir) { DIR *dp; struct stat stat; struct dirent *ep; time_t newest = (time_t)0; - uint32_t newest_index = 0; + uint32_t newest_index = -1; int index; char cwd[100]; diff --git a/bin/nfextract.c b/bin/nfextract.c index 11fe608..44e7d1a 100644 --- a/bin/nfextract.c +++ b/bin/nfextract.c @@ -81,7 +81,7 @@ static void extract_all(const char *storage_dir) { struct dirent *ep; int i, index, max_index = -1; char *trunk_files[MAX_TRUNK_ID]; - memset(trunk_files, sizeof(trunk_files), 0); + memset(trunk_files, 0, sizeof(trunk_files)); ERR(!(dp = opendir(storage_dir)), "Can't open the storage directory"); while ((ep = readdir(dp))) { diff --git a/lib/common.c b/lib/common.c index e1f7e91..cbd7e0f 100644 --- a/lib/common.c +++ b/lib/common.c @@ -32,7 +32,7 @@ int nfl_check_dir(const char *storage_dir) { int nfl_storage_match_index(const char *fn) { static regex_t regex; static bool compiled = false; - regmatch_t match[1]; + regmatch_t match[2]; int ret; if (unlikely(!strcmp(fn, ".") || !strcmp(fn, ".."))) |