Skip to content

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Aug 9, 2025

libc is allowed to provide any functions as macros (7.1.4p1 in C23).

This means that libc is allowed to provide a free(3) macro, which could look like

#define free(p)  __free(p)

And that would be expanded by the preprocessor in our code, turning our structure members into some code that won't work (or even worse, it might misbehave).

So, fix this undefined behavior.


Revisions:

v1b
  • Rebase
$ git rd 
1:  9bd4846f = 1:  40c6de86 lib/commonio.c: Parenthesize calls that look like libc APIs
v1c
  • Rebase
$ git rd 
1:  40c6de86 = 1:  cfd05116 lib/commonio.c: Parenthesize calls that look like libc APIs

@hallyn
Copy link
Member

hallyn commented Aug 9, 2025

Does any libc do this?

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Aug 10, 2025

Does any libc do this?

I'm experimenting with an _Optional qualifier that is being debated within the C Committee.
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3422.pdf

I've installed the following header (written by the committee member that authored the proposal of _Optional) in my /usr/local/include/:
https://github.com/chrisbazley/CBUtilLib/blob/main/Optional.h

It wraps libc APIs to add the qualifier where appropriate. And it indeed does this by necessity.

Cc: @chrisbazley

libc is allowed to provide any functions as macros (7.1.4p1 in C23).

This means that libc is allowed to provide a free(3) macro, which could
look like

	#define free(p)  __free(p)

And that would be expanded by the preprocessor in our code, turning our
structure members into some code that won't work (or even worse, it
might misbehave).

So, fix this undefined behavior.

Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar alejandro-colomar added the Simpler A good issue for a new beginner label Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simpler A good issue for a new beginner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants