public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: GNU C Library <libc-alpha@sourceware.org>
Subject: [PATCH] remove attribute access from regexec
Date: Fri, 13 Aug 2021 12:26:38 -0600	[thread overview]
Message-ID: <15a32181-8060-4135-cb72-9e79831697d5@gmail.com> (raw)

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)

             reply	other threads:[~2021-08-13 18:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 18:26 Martin Sebor [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15a32181-8060-4135-cb72-9e79831697d5@gmail.com \
    --to=msebor@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).