diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2022-02-17 21:43:58 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2022-02-17 21:43:58 -0500 |
commit | 476219e3129d1e7da0030b17fd0421a5dd70fd39 (patch) | |
tree | b37cfa9eb98dbc134c61834c708255f48a245ec6 | |
parent | e28b47c3bd9ef2a50c30ec458b6115612fbddab7 (diff) | |
download | cleanpath-476219e3129d1e7da0030b17fd0421a5dd70fd39.tar.gz |
Bug fixes
* cleanpath_read no longer updates path->part_nelem
* Moved path->part_nelem update to cleanpath_filter
-rw-r--r-- | lib/cleanpath.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/cleanpath.c b/lib/cleanpath.c index 468c610..c201e5e 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -88,8 +88,12 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern break; } - if (match) + if (match) { *path->part[i] = '\0'; + // Update count of unfiltered parts + if (path->part_nelem) + path->part_nelem--; + } } } @@ -102,32 +106,18 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern char *cleanpath_read(struct CleanPath *path) { char *result; size_t result_len; - size_t part_count; - size_t empty; result = calloc(path->data_len, sizeof(char)); if (result == NULL) { goto cleanpath_read__failure; } - // Update number of elements in the path post-filter - empty = 0; - for (part_count = 0; path->part[part_count] != NULL; part_count++) { - if (!strlen(path->part[part_count])) { - empty++; - continue; - } - } - path->part_nelem = part_count - empty; - - for (size_t i = 0; i < part_count; i++) { + for (size_t i = 0; path->part[i] != NULL; i++) { // Ignore filtered paths if (!strlen(path->part[i])) { continue; } strcat(result, path->part[i]); - if (i == part_count - 1) - continue; strcat(result, path->sep); } |