-
Notifications
You must be signed in to change notification settings - Fork 7.3k
net: http: server: Avoid compiler warnings for zero-length-arrays #87690
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
net: http: server: Avoid compiler warnings for zero-length-arrays #87690
Conversation
I just wonder why the compiler thinks there is an error here, what is the actual issue? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was originally implemented with the buffer sizes set to zero if the feature is disabled so that the code referencing the headers
and buffer
fields does not need to be conditionally compiled, and we can just enable or disable it using if(IS_ENABLED(CONFIG_HTTP_SERVER_HEADER_CAPTURE))
instead. As well as being more readable this has the advantage that the code is always compile-checked regardless of whether the option is enabled, and just gets optimised out at compile/link time if the option is disabled.
Based on this, I think we're likely to run into some build failures if we just #ifdef
out the struct fields in the header without touching the C files (CI hasn't run yet so this should show up any issues we do have).
Make sense. Should we put there size to Edit: AFAIK in C every object has size at least = 1 anyway to ensure unique addresses?
|
We could try to set the value to |
This is related to #87650 |
OK, it looks like the warning is a false positive since the buffer length is checked before the call to I wonder if swapping the |
Thanks for the quick response. I will double check. |
|
Does not work in this case: zephyr/include/zephyr/net/http/server.h:379:23: error: flexible array member not at end of struct
379 | unsigned char buffer[HTTP_SERVER_CAPTURE_HEADER_BUFFER_SIZE];
| ^~~~~~
zephyr/include/zephyr/net/http/server.h:382:28: error: flexible array member not at end of struct
382 | struct http_header headers[HTTP_SERVER_CAPTURE_HEADER_COUNT];
| ^~~~~~~ |
Avoid compiler warnings for zero-length-arrays in the http-server. By using memcpy instead of strcpy. Signed-off-by: Cla Mattia Galliard <[email protected]>
2a26a3a
to
75ce693
Compare
Adjusted to use |
The zephyr/include/zephyr/sys/util.h Line 142 in d02bc50
I am not suggesting that we use that macro here, just a note that it can be done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the compiler is happy with memcpy
instead, then that's good with me
Avoid compiler warnings for zero-length-arrays in the http-server.
Note: warnings only visible if
CONFIG_NO_OPTIMIZATIONS
is selected.Note2: Alternative approach would be to set length to
1
instead of0
. Would that be prefered?