libcamera/test
Laurent Pinchart 7f33dfc100 libcamera: Avoid variable-length arrays
Unlike in C where they have been standardized since C99, variable-length
arrays in C++ are an extension supported by gcc and clang. Clang started
warning about this with -Wall in version 18:

src/libcamera/ipc_unixsocket.cpp:250:11: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
  250 |         char buf[CMSG_SPACE(num * sizeof(uint32_t))];
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

One simple option is to disable the warning. However, usage of VLAs in
C++ is discouraged by some, usually due to security reasons, based on
the rationale that developers are often unaware of unintentional use of
VLAs and how they may affect the security of the code when the array
size is not properly validated.

This rationale may sound dubious, as the most commonly proposed fix is
to replace VLAs with vectors (or just arrays dynamically allocated with
new() wrapped in unique pointers), without adding any size validation.
This will not produce much better results. However, keeping the VLA
warning and converting the code to dynamic allocation may still be
slightly better, as it can prompt developers to notice VLAs and check if
size validation is required.

For these reasons, convert all VLAs to std::vector. Most of the VLAs
don't need extra size validation, as the size is bound through different
constraints (e.g. image width for line buffers). An arguable exception
may be the buffers in IPCUnixSocket::sendData() and
IPCUnixSocket::recvData() as the number of fds is not bound-checked
locally, but we will run out of file descriptors before we could
overflow the buffer size calculation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Acked-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2024-07-31 01:22:13 +03:00
..
camera test: camera: Increase timeout for vimc capture tests 2024-06-03 11:53:01 +03:00
controls libcamera: Drop remaining file name from header comment blocks 2024-05-09 23:31:15 +03:00
gstreamer gstreamer: allocator: Ensure camera manager stay alive 2024-07-25 11:44:32 +01:00
ipa meson: Group libipa and libipa_includes in a dependency object 2024-06-11 16:39:22 +03:00
ipc libcamera: Avoid variable-length arrays 2024-07-31 01:22:13 +03:00
libtest libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
log libcamera: Drop remaining file name from header comment blocks 2024-05-09 23:31:15 +03:00
media_device libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
process libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
py py: unittests.py: Fix type checker warnings 2023-06-04 16:10:51 +03:00
serialization libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
stream libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
v4l2_compat libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
v4l2_subdevice libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
v4l2_videodevice test: v4l2_videodevice: Increase timeout for vimc capture tests 2024-06-03 11:53:10 +03:00
bayer-format.cpp libcamera: Drop remaining file name from header comment blocks 2024-05-09 23:31:15 +03:00
byte-stream-buffer.cpp libcamera: Drop remaining file name from header comment blocks 2024-05-09 23:31:15 +03:00
camera-sensor.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
color-space.cpp test: Add a ColorSpace test 2022-08-26 01:04:27 +03:00
delayed_controls.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
event-dispatcher.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
event-thread.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
event.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
fence.cpp test: fence: Increase timeout for fence test 2024-06-03 11:53:07 +03:00
file.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
flags.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
geometry.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
hotplug-cameras.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
mapped-buffer.cpp test: Remove using namespace in header files 2021-10-15 05:05:43 +03:00
meson.build test: Don't add current build directory to include path 2024-05-07 19:35:43 +03:00
message.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
object-delete.cpp libcamera: Drop remaining file name from header comment blocks 2024-05-09 23:31:15 +03:00
object-invoke.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
object.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
pixel-format.cpp libcamera/base: Move utils to the base library 2021-06-25 16:11:02 +01:00
public-api.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
shared-fd.cpp libcamera: Drop remaining file name from header comment blocks 2024-05-09 23:31:15 +03:00
signal-threads.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
signal.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
span.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
threads.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
timer-fail.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
timer-thread.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
timer.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
transform.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
unique-fd.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00
utils.cpp test: utils: Extend utils::hex() test to 8-bit and 16-bit values 2024-07-04 14:03:59 +03:00
yaml-parser.cpp libcamera: Drop file name from header comment blocks 2024-05-08 22:39:50 +03:00