public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] remove attribute access from regexec
@ 2021-08-13 18:26 Martin Sebor
  2021-08-13 20:11 ` Paul Eggert
  0 siblings, 1 reply; 22+ messages in thread
From: Martin Sebor @ 2021-08-13 18:26 UTC (permalink / raw)
  To: GNU C Library

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)

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2021-10-19 17:07 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 18:26 [PATCH] remove attribute access from regexec Martin Sebor
2021-08-13 20:11 ` Paul Eggert
2021-08-13 21:30   ` Martin Sebor
2021-08-13 22:34     ` Paul Eggert
2021-08-14 20:08       ` Martin Sebor
2021-08-18 15:53         ` [PATCH v2] " Martin Sebor
2021-08-18 19:52         ` [PATCH] " Paul Eggert
2021-08-19 23:50           ` [PATCH v3] " Martin Sebor
2021-08-22  5:06             ` Paul Eggert
2021-08-26 15:06               ` Martin Sebor
2021-08-26 16:24                 ` Paul Eggert
2021-08-26 16:47                   ` Martin Sebor
2021-08-27  8:52                     ` Paul Eggert
2021-08-27 16:34                       ` Martin Sebor
2021-08-27 17:50                         ` Allow #pragma GCC in headers in conformtest [committed] (was: Re: [PATCH v3] remove attribute access from regexec) Joseph Myers
2021-08-27 18:57                         ` [PATCH v3] remove attribute access from regexec Paul Eggert
2021-09-20 20:46                           ` Joseph Myers
2021-09-21  6:52                             ` Paul Eggert
2021-09-21 13:48                               ` Joseph Myers
2021-09-21 15:00                                 ` Paul Eggert
2021-10-19 16:39             ` Carlos O'Donell
2021-10-19 17:06               ` Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).