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

MacOS-specific -Werror=maybe-unitialised due to malloc_size signature #453

Closed
andrjohns opened this issue Jul 1, 2024 · 0 comments · Fixed by #454
Closed

MacOS-specific -Werror=maybe-unitialised due to malloc_size signature #453

andrjohns opened this issue Jul 1, 2024 · 0 comments · Fixed by #454

Comments

@andrjohns
Copy link
Contributor

Compiling on MacOS with GCC >= 11 will fail with error:

[ 23%] Building C object CMakeFiles/qjs.dir/quickjs.c.o
In file included from /Users/andrew/Git/quickjs-ng/quickjs.c:43:
In function 'js__malloc_usable_size',
    inlined from 'js_def_malloc' at /Users/andrew/Git/quickjs-ng/quickjs.c:1706:51:
/Users/andrew/Git/quickjs-ng/cutils.h:488:12: error: 'ptr' may be used uninitialized [-Werror=maybe-uninitialized]
  488 |     return malloc_size(ptr);

This is because the js__malloc_usable_size function is defined using malloc_size on MacOS, which has signature:

size_t malloc_size(const void * __unsafe_indexable ptr);

From GCC >=11, -Wmaybe-uninitialised has stricter warnings on inputs to a const-qualified parameter, which has caused issues already. You can see a small reprex of this behaviour on godbolt

I believe this is also the cause of the warnings seen by @barracuda156 in this comment/issue

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 a pull request may close this issue.

1 participant