[PATCH] remove attribute access from regexec
Martin Sebor
msebor@gmail.com
Fri Aug 13 18:26:38 GMT 2021
A recent GCC enhancement to detect accesses by functions declared
with attribute access that are in conflict with the mode specified
by the attribute triggers a warning for the definition of regexec:
regexec.c: In function ‘__regexec’:
regexec.c:204:13: warning: ‘*pmatch.rm_so’ may be used uninitialized
[-Wmaybe-uninitialized]
regexec.c:192:101: note: accessing argument 4 of a function declared
with attribute ‘access (write_only, 4, 3)’
The attribute was added based on the POSIX description of
the function that implies the pmatch array referenced by it is
write-only. However, when the REG_STARTEND bit is set in flags,
Glibc also reads from the object. This seems to be an extension
to POSIX that's not mentioned in the Glibc manual but that is
documented in the Linux man pages:
https://man7.org/linux/man-pages/man3/regcomp.3.html
The patch below changes the attribute's mode to read_write to
reflect this extension.
Martin
diff --git a/posix/regex.h b/posix/regex.h
index 14fb1d8364..ba8351f873 100644
--- a/posix/regex.h
+++ b/posix/regex.h
@@ -656,7 +656,7 @@ extern int regexec (const regex_t *_Restrict_ __preg,
const char *_Restrict_ __String, size_t __nmatch,
regmatch_t __pmatch[_Restrict_arr_],
int __eflags)
- __attr_access ((__write_only__, 4, 3));
+ __attr_access ((__read_write__, 4, 3));
extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
char *_Restrict_ __errbuf, size_t __errbuf_size)
More information about the Libc-alpha
mailing list