Bug 1671507 - Do not use unprefixed macros in public header file
Summary: Do not use unprefixed macros in public header file
Keywords:
Status: CLOSED DUPLICATE of bug 1672231
Alias: None
Product: Fedora
Classification: Fedora
Component: samba
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Guenther Deschner
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-01-31 18:44 UTC by Lukas Slebodnik
Modified: 2019-02-15 10:28 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-02-15 10:28:27 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Lukas Slebodnik 2019-01-31 18:44:58 UTC
Description of problem:


Version-Release number of selected component (if applicable):
rpm -qf /usr/include/samba-4.0/ndr.h 
samba-devel-4.10.0-0.0.rc1.fc30.x86_64

How reproducible:
Deterministic

Steps to Reproduce:
1. dnf install -y gcc samba-devel pkgconf-pkg-config
2. cat >test.c <<EOF
#include <ndr.h>

#define ZERO_STRUCT(x) cool_function((char *)&(x), sizeof(x), 0, sizeof(x))

int main(void) {
    return 0;
}
EOF
3. gcc `pkg-config --cflags ndr` pok.c

Actual results:
pok.c:3: warning: "ZERO_STRUCT" redefined
    3 | #define ZERO_STRUCT(x) memset((char *)&(x), sizeof(x), 0, sizeof(x))
      | 
In file included from /usr/include/samba-4.0/ndr.h:29,
                 from pok.c:1:
/usr/include/samba-4.0/util/memory.h:54: note: this is the location of the previous definition
   54 | #define ZERO_STRUCT(x) memset_s((char *)&(x), sizeof(x), 0, sizeof(x))
      |

Expected results:
No warnings are generated.

Additional info:

I assume that the header file /usr/include/samba-4.0/util/memory.h is public because the macro discard_const (defined in util/memory.h) is used in another macro in ndr.h

sh$ grep -n -C5 discard_const /usr/include/samba-4.0/ndr.h 
373-#define NDR_PULL_SET_MEM_CTX(ndr, mem_ctx, flgs) do {\
374-    if ( !(flgs) || (ndr->flags & flgs) ) {\
375-            if (!(mem_ctx)) {\
376-                    return ndr_pull_error(ndr, NDR_ERR_ALLOC, "NDR_PULL_SET_MEM_CTX(NULL): %s\n", __location__); \
377-            }\
378:            ndr->current_mem_ctx = discard_const(mem_ctx);\
379-    }\
380-} while(0)
381-
382-#define _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr) do {\
383-    if (!ndr->current_mem_ctx) {\


Making macros without any prefix is not idea way. People will need to undefine then and then define with different content.

Comment 1 Lukas Slebodnik 2019-01-31 18:47:34 UTC
IMHO, samba-devel should either provides prefixed macros in /usr/include/samba-4.0/util/memory.h
or they should not be provided at all + and you might replace usage of `discard_const` in public ndr.h with (void *)(uintptr_t)

Comment 2 Lukas Slebodnik 2019-02-01 09:06:29 UTC
BTW I know that these macros are in samba for ages. But they have never been public,

If you want to have them public then they should have unique prefix. (Unfortunately, C does not have namespaces)

Comment 3 Andreas Schneider 2019-02-04 17:29:28 UTC
The file has:

53 #ifndef ZERO_STRUCT
54 #define ZERO_STRUCT(x) memset_s((char *)&(x), sizeof(x), 0, sizeof(x))                                                                                                                   
55 #endif

so if you define your ZERO_STRUCT first, it will be overwritten. However, the question is if memory.h should be a public header and included in others. The same appies for byteorder.h.

Comment 4 Lukas Slebodnik 2019-02-15 09:02:07 UTC
This BZ can be closed as a duplicate of 1672231

https://src.fedoraproject.org/rpms/samba/c/57d362cb8f13e5dfa0f19d868852f67f8e30f3ff?branch=master

Comment 5 Andreas Schneider 2019-02-15 10:28:27 UTC
Closing, thanks!

*** This bug has been marked as a duplicate of bug 1672231 ***


Note You need to log in before you can comment on or make changes to this bug.