Skip to content

Avoid variable length arrays (VLAs)#82

Merged
mguentner merged 1 commit into
mguentner:masterfrom
alperak:fix-vla
Jul 9, 2025
Merged

Avoid variable length arrays (VLAs)#82
mguentner merged 1 commit into
mguentner:masterfrom
alperak:fix-vla

Conversation

@alperak
Copy link
Copy Markdown
Contributor

@alperak alperak commented Jul 9, 2025

While disabling VLA warnings is possible, using VLAs in C++ is discouraged due to portability concerns and potential security issues, especially if array sizes aren't explicitly validated. Although switching to dynamic allocation doesn't guarantee improved security on its own, it makes code more compliant with the C++ standard and improves compatibility with modern compilers like Clang.

Fix:

sctpthread.cpp:95:18: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
95 | uint8_t buffer[m_linkMtuSize];
| ^~~~~~~~~~~~~

While disabling VLA warnings is possible, using VLAs in C++ is discouraged due to portability concerns and potential security issues, especially if array sizes aren't explicitly validated. Although switching to dynamic allocation doesn't guarantee improved security on its own, it makes code more compliant with the C++ standard and improves compatibility with modern compilers like Clang.

Fix:

sctpthread.cpp:95:18: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
   95 |   uint8_t buffer[m_linkMtuSize];
      |                  ^~~~~~~~~~~~~

Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this pull request Jul 9, 2025
- Appends -Wno-error=vla-cxx-extension to CXXFLAGS as a temporary workaround for the following Clang error:

   sctpthread.cpp:95:18: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
      95 |   uint8_t buffer[m_linkMtuSize];
         |                  ^~~~~~~~~~~~~

An upstream fix has been proposed: mguentner/cannelloni#82

Please remove this workaround once the upstream patch is merged or fixed in some other way. Make sure it is fixed in the new version.

- Drop 0001-include-bits-stdc-.h-only-when-using-libstdc.patch because already fixed in newer version.

Changelog:

mguentner/cannelloni@v1.1.0...v2.0.0

Fix:

| CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
|   Compatibility with CMake < 3.5 has been removed from CMake.
|
|   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
|   to tell CMake that the project requires at least <min> but has been updated
|   to work with policies introduced by <max> or earlier.
|
|   Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
|
|
| -- Configuring incomplete, errors occurred!

Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
@mguentner mguentner merged commit 5a6a6a7 into mguentner:master Jul 9, 2025
4 checks passed
@mguentner
Copy link
Copy Markdown
Owner

Thank you!

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