From 3708bd74ea9d72edf5877617f6f48d1c7984882f Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 25 Mar 2024 14:33:01 +0100 Subject: [PATCH] fixed VLAs in C++ files see commit @{2} description --- src/utils/macros.h | 4 +++- src/utils/video_pattern_generator.cpp | 4 ++-- src/utils/worker.cpp | 8 +++++--- src/video_codec.h | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/macros.h b/src/utils/macros.h index 8c7029712d..9d452d9702 100644 --- a/src/utils/macros.h +++ b/src/utils/macros.h @@ -113,8 +113,10 @@ #define OPTIMIZED_FOR for #endif +/// the following limits are used mostly for static array allocations enum { - STR_LEN = 2048, ///< "standard" string length placeholder + MAX_CPU_CORES = 256, ///< maximal expected CPU core count + STR_LEN = 2048, ///< "standard" string length placeholder }; /// expands to true value if from tok in format = is prefix of key diff --git a/src/utils/video_pattern_generator.cpp b/src/utils/video_pattern_generator.cpp index 0d82f7ae85..910a0e8f71 100644 --- a/src/utils/video_pattern_generator.cpp +++ b/src/utils/video_pattern_generator.cpp @@ -647,12 +647,12 @@ struct gray_video_pattern_generator : public video_pattern_generator { int col = 0; while (col < 0xFF) { int pixels = get_pf_block_pixels(color_spec); - unsigned char rgba[pixels * 4]; + unsigned char rgba[MAX_PFB_SIZE * 4]; for (int i = 0; i < pixels * 4; ++i) { rgba[i] = (i + 1) % 4 != 0 ? col : 0xFFU; // handle alpha } int dst_bs = get_pf_block_bytes(color_spec); - unsigned char dst[dst_bs]; + unsigned char dst[MAX_PFB_SIZE]; testcard_convert_buffer(RGBA, color_spec, dst, rgba, pixels, 1); auto next_frame = vector(data_len); diff --git a/src/utils/worker.cpp b/src/utils/worker.cpp index 277f7e6c79..d4891ebaa2 100644 --- a/src/utils/worker.cpp +++ b/src/utils/worker.cpp @@ -42,10 +42,12 @@ #include #include -#include "utils/misc.h" // get_cpu_core_count +#include "utils/macros.h" // for MAX_CPU_CORES +#include "utils/misc.h" // get_cpu_core_count #include "utils/thread.h" #include "utils/worker.h" +using std::min; using std::queue; using std::set; using std::vector; @@ -329,8 +331,8 @@ static void *respawn_parallel_task(void *arg) { */ void respawn_parallel(void *in, void *out, size_t nmemb, size_t size, respawn_parallel_callback_t c, void *udata) { - int threads = get_cpu_core_count(); - struct respawn_parallel_data data[threads]; + const int threads = min(get_cpu_core_count(), MAX_CPU_CORES); + struct respawn_parallel_data data[MAX_CPU_CORES]; for (int i = 0; i < threads; ++i) { data[i].c = c; diff --git a/src/video_codec.h b/src/video_codec.h index 1caa56bd48..fe7b3e6252 100644 --- a/src/video_codec.h +++ b/src/video_codec.h @@ -62,6 +62,7 @@ extern "C" { #define MAX_BPS 8 /* for Y416 */ ///< maximal (average) number of pixels per know pixel formats (up-round if needed) #define MAX_PADDING 64 ///< maximal padding in bytes that may be needed to align to pixfmt block size for Y416->R12L: ///< 64 = vc_linesize(8 /*maximal block pix count (R12L)*/, Y416 /*codec with maximal lenght of 1st arg-sized block*/) +#define MAX_PFB_SIZE 8 ///< maximal pixfmt block size (R12L - 8 B) #define PIX_BLOCK_LCM 24 ///< least common multiple of all pixfmt block sizes in pixels (codec_info_t::block_size/codec_info_t::bpp). "contributors:" 8 R12L, 6 v210 /// Prints list of suppored codecs for video module