summaryrefslogtreecommitdiff
path: root/lib-src/etags.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-05-31 01:19:31 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-05-31 01:26:47 -0700
commita1c19dfca4b1e0b84a958aee33c8212dc69cd2cb (patch)
treec89d553de7ec5710a8bde01b5fd2682b331f0cab /lib-src/etags.c
parentd94890404e91d5ba50afaa4bc27b9c655dbed5f1 (diff)
downloademacs-a1c19dfca4b1e0b84a958aee33c8212dc69cd2cb.tar.gz
Pacify GCC 12 -Wanalyzer-use-of-uninitialized-value
* lib-src/etags.c (readline_internal): Do not copy a pointer to freed storage, as that has undefined behavior even if the pointer is not dereferenced. (relative_filename): Avoid a backward scan by remembering where the last slash was. This is a bit faster, and pacifies a GCC false alarm.
Diffstat (limited to 'lib-src/etags.c')
-rw-r--r--lib-src/etags.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index ea99ed9f396..f76dda7936b 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -7248,8 +7248,8 @@ readline_internal (linebuffer *lbp, FILE *stream, char const *filename)
{
/* We're at the end of linebuffer: expand it. */
xrnew (buffer, lbp->size, 2);
+ p = buffer + lbp->size;
lbp->size *= 2;
- p += buffer - lbp->buffer;
pend = buffer + lbp->size;
lbp->buffer = buffer;
}
@@ -7670,21 +7670,21 @@ relative_filename (char *file, char *dir)
{
char *fp, *dp, *afn, *res;
ptrdiff_t i;
+ char *dir_last_slash UNINIT;
/* Find the common root of file and dir (with a trailing slash). */
afn = absolute_filename (file, cwd);
fp = afn;
dp = dir;
while (*fp++ == *dp++)
- continue;
- fp--, dp--; /* back to the first differing char */
+ if (dp[-1] == '/')
+ dir_last_slash = dp - 1;
#ifdef DOS_NT
- if (fp == afn && afn[0] != '/') /* cannot build a relative name */
- return afn;
+ if (fp - 1 == afn && afn[0] != '/')
+ return afn; /* Cannot build a relative name. */
#endif
- do /* look at the equal chars until '/' */
- fp--, dp--;
- while (*fp != '/');
+ fp -= dp - dir_last_slash;
+ dp = dir_last_slash;
/* Build a sequence of "../" strings for the resulting relative file name. */
i = 0;