Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid alloca in libpsl and tests #231

Merged
merged 3 commits into from
Feb 11, 2024
Merged

Avoid alloca in libpsl and tests #231

merged 3 commits into from
Feb 11, 2024

Conversation

rockdaboot
Copy link
Owner

alloca() needs special treatment for Windows and possibly other systems. The implementation also is compiler-specific. alloca() in general is considered "dangerous" (similar to variable-length arrays (VLAs)).

This PR drops the usage of alloca() for the aforementioned reasons.

# include <alloca.h>
#elif defined _WIN32
# include <malloc.h>
# include <malloc.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean stdlib.h here? This is a glibc-ism.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding https://learn.microsoft.com/de-de/cpp/c-runtime-library/reference/malloc?view=msvc-170, malloc() requires stdlib.h and malloc.h. The first is included further up, unconditionally.

Glibc only requires stdlib.h.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but for non Windows the canonical definition is stdlib.h -- malloc.h may not exist and isn't documented as the correct way to do it.

It does exist on glibc but it doesn't exist on macOS, which caused a build failure.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, the include was in the #ifndef _WIN32 path, should have be in the #else path. Fixed it and force-pushed.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eli-schwartz Can you check again (see my comment #231 (comment)) and unblock the PR if OK?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, sorry, lost track of that.

@rockdaboot rockdaboot force-pushed the avoid-alloca branch 2 times, most recently from 21227e9 to 272cd35 Compare February 10, 2024 16:54
@eli-schwartz eli-schwartz dismissed their stale review February 11, 2024 03:03

macOS build failures resolved, looks good now

@eli-schwartz
Copy link
Collaborator

eli-schwartz commented Feb 11, 2024

Rebased in order to refresh CI checks, everything looks good.

Apologies for the holdup.

@eli-schwartz eli-schwartz merged commit e8ef87a into master Feb 11, 2024
9 of 13 checks passed
@eli-schwartz eli-schwartz deleted the avoid-alloca branch February 11, 2024 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants