Skip to content

Commit

Permalink
compat/regex: move stdlib.h up in inclusion chain
Browse files Browse the repository at this point in the history
In Linux with musl libc, we have this inclusion chain:

compat/regex/regex.c:69
`-> compat/regex/regex_internal.h
   `-> /usr/include/stdlib.h
      `-> /usr/include/features.h
      `-> /usr/include/alloca.h

In that inclusion chain, `<features.h>` claims it's _BSD_SOURCE
compatible when it's NOT asked to be either
{_POSIX,_GNU,_XOPEN,_BSD}_SOURCE, or __STRICT_ANSI__.
And, `<stdlib.h>` will include `<alloca.h>` to be compatible with
software written for GNU and BSD. Thus, redefine `alloca` macro,
which was defined before at compat/regex/regex.c:66.

Considering this is only compat code, we've taken from other project,
it's not our business to decide which source should we adhere to.

Include `<stdlib.h>` early to prevent the redefinition of alloca.
This also remove a potential warning about alloca not defined on:
	#undef alloca

Helped-by: Ramsay Jones <[email protected]>
Signed-off-by: Đoàn Trần Công Danh <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
sgn authored and dscho committed Jan 13, 2024
1 parent bbb067e commit a24969d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 1 addition & 0 deletions compat/regex/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
GNU regex allows. Include it before <regex.h>, which correctly
#undefs RE_DUP_MAX and sets it to the right value. */
#include <limits.h>
#include <stdlib.h>

#include <regex.h>
#include "regex_internal.h"
Expand Down
1 change: 0 additions & 1 deletion compat/regex/regex_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <langinfo.h>
Expand Down

0 comments on commit a24969d

Please sign in to comment.