git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 4, 2010, 17:54 UTC
Message-ID
<7v8w2d972o.fsf@alter.siamese.dyndns.org>
In-Reply-To
<AANLkTimBzC7f7teH8Rriykg7o5kwX6mD2g2q-0yOXSiF@mail.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 13 quoted lines
> Oh it's a bug in NetBSD, sorry for not being explicit about that:
>
>     $ grep S_ISREG /usr/include/sys/stat.h
>     #define S_ISREG(m)      ((m & _S_IFMT) == _S_IFREG)     /* regular file */
>
>     $ grep S_ISREG /usr/include/linux/stat.h
>     #define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
>
> I.e. GCC sees `S_IFREG | 0644 & _S_IFMT' on NetBSD but `(S_IFREG |
> 0644) & _S_IFMT' on Linux.
>
> Since bitwise AND (&) has precedence over bitwise OR it's probably a
> logic error on NetBSD too, not just an annoying warning.

In that case, I'd prefer to work this around at the definition of canon_mode(), like

    /*
     * extra ()-pair around S_ISREG() and friends to work around platform
     * header with buggy definitions like
     * #define S_ISREG(x) ((x & _S_IFMT) == _S_IFREG)
     */
    #define canon_mode(mode) \
    	(S_ISREG((mode)) ? (S_IFREG | ce_permissions(mode)) : \
        ...

instead of contaminating the calling sites. Otherwise new calling sites we will add in the future need to be aware of the same bug for no good reason.

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 4 of 13 in “diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning”
  1. diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warningÆvar Arnfjörð Bjarmason, Oct 4, 2010
  2. Jonathan NiederOct 4, 2010
  3. Ævar Arnfjörð BjarmasonOct 4, 2010
  4. Junio C HamanoOct 4, 2010
  5. cache.h: work around broken NetBSD system headersÆvar Arnfjörð Bjarmason, Oct 4, 2010
  6. Ævar Arnfjörð BjarmasonOct 4, 2010
  7. Jonathan NiederOct 4, 2010
  8. Jonathan NiederOct 4, 2010
  9. René ScharfeOct 4, 2010
  10. Matthieu MoyOct 4, 2010
  11. Junio C HamanoOct 4, 2010
  12. René ScharfeOct 4, 2010
  13. yj2133011Oct 4, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.