diff options
author | Colin Watson <cjwatson@debian.org> | 2022-09-24 14:15:27 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2022-09-24 14:15:27 +0100 |
commit | 26b957306113c1cf47133268a938f32c31722ab3 (patch) | |
tree | 05e5485b0a423e1f714eb46d3044ac3e06ad690f | |
parent | e6194cf2e74699c08b3cf3ccbc780c473561f30f (diff) |
Stop using the addr field of struct mandata
The `addr` field of `struct mandata` is just intended as an internal
buffer, but some functions were extracting information from it in
complicated ways, which made it difficult to refactor the memory
allocation here. Use different approaches.
* src/check_mandirs (test_manfile): Calculate `len` using `comp_info`.
This duplicates some of what `filename_info` does, but it's just some
cheap string manipulation, and it expresses what we want in a less
confusing way (the length of the file name with any compression
extension removed).
* src/descriptions_store.c (store_descriptions): Check whether `path` is
a prefix of `trace_name` rather than of `trace_info->addr`.
`trace_info->addr` is always itself a prefix of `trace_name`, so if
`path` is not a prefix of `trace_name` then it can't be a prefix of
`trace_info->addr`.
-rw-r--r-- | src/check_mandirs.c | 11 | ||||
-rw-r--r-- | src/descriptions_store.c | 3 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/check_mandirs.c b/src/check_mandirs.c index b75235dc..0c3b534c 100644 --- a/src/check_mandirs.c +++ b/src/check_mandirs.c @@ -62,6 +62,7 @@ #include "manconfig.h" #include "appendstr.h" +#include "compression.h" #include "debug.h" #include "fatal.h" #include "filenames.h" @@ -161,6 +162,7 @@ void test_manfile (MYDBM_FILE dbf, const char *file, const char *path) const char *ult; struct lexgrog lg; struct mandata *info, *exists; + struct compression *comp; struct stat buf; size_t len; gl_list_t ult_trace = NULL; @@ -174,9 +176,12 @@ void test_manfile (MYDBM_FILE dbf, const char *file, const char *path) manpage_base = info->name; /* steal memory */ info->name = NULL; - len = strlen (info->addr) + 1; /* skip over directory name */ - len += strlen (info->addr + len) + 1; /* skip over base name */ - len += strlen (info->addr + len); /* skip over section ext */ + comp = comp_info (file, 1); + if (comp) { + len = strlen (comp->stem); + free (comp->stem); + } else + len = strlen (file); /* to get mtime info */ (void) lstat (file, &buf); diff --git a/src/descriptions_store.c b/src/descriptions_store.c index 73b28112..73d8938d 100644 --- a/src/descriptions_store.c +++ b/src/descriptions_store.c @@ -109,8 +109,7 @@ void store_descriptions (MYDBM_FILE dbf, gl_list_t descs, struct mandata *info, !STREQ (trace_info->name, desc->name)) goto next_trace; - if (path && - !is_prefix (path, trace_info->addr)) { + if (path && !is_prefix (path, trace_name)) { /* Link outside this manual * hierarchy; skip this description. */ |