[libcamera-devel] [PATCH 7/8] cam: options: Don't initialise variable-length arrays
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Fri Apr 26 17:01:54 CEST 2019
According to clang, variable-length arrays can't be initialised. Don't
do so, and explicitly set the last element to 0 instead.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
src/cam/options.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 172d40f76a05..b80d361eaaf4 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -382,8 +382,8 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv)
* Allocate short and long options arrays large enough to contain all
* options.
*/
- char shortOptions[options_.size() * 3 + 2] = {};
- struct option longOptions[options_.size() + 1] = {};
+ char shortOptions[options_.size() * 3 + 2];
+ struct option longOptions[options_.size() + 1];
unsigned int ids = 0;
unsigned int idl = 0;
@@ -419,6 +419,9 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv)
}
}
+ shortOptions[ids] = '\0';
+ memset(&longOptions[idl], 0, sizeof(longOptions[idl]));
+
opterr = 0;
while (true) {
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list