From: Rosen Penev <rosenp@gmail.com>
To: linux-media@vger.kernel.org
Subject: [PATCH 5/8] v4l2-info: remove a strange sizeof usage
Date: Wed, 21 Apr 2021 00:20:32 -0700 [thread overview]
Message-ID: <20210421072035.4188497-5-rosenp@gmail.com> (raw)
In-Reply-To: <20210421072035.4188497-1-rosenp@gmail.com>
The array has a nullptr and 0 member for some reason. Remove and convert
loop to a for range one.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
utils/common/v4l2-info.cpp | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/utils/common/v4l2-info.cpp b/utils/common/v4l2-info.cpp
index cb3cb91f7..0359cf137 100644
--- a/utils/common/v4l2-info.cpp
+++ b/utils/common/v4l2-info.cpp
@@ -3,6 +3,8 @@
* Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
*/
+#include <array>
+
#include <v4l2-info.h>
static std::string num2s(unsigned num, bool is_hex = true)
@@ -411,21 +413,20 @@ std::string mbus2s(unsigned flags, bool is_hsv)
return flags2s(flags, mbus_ycbcr_def);
}
-static const flag_def selection_targets_def[] = {
- { V4L2_SEL_TGT_CROP_ACTIVE, "crop" },
- { V4L2_SEL_TGT_CROP_DEFAULT, "crop_default" },
- { V4L2_SEL_TGT_CROP_BOUNDS, "crop_bounds" },
- { V4L2_SEL_TGT_COMPOSE_ACTIVE, "compose" },
- { V4L2_SEL_TGT_COMPOSE_DEFAULT, "compose_default" },
- { V4L2_SEL_TGT_COMPOSE_BOUNDS, "compose_bounds" },
- { V4L2_SEL_TGT_COMPOSE_PADDED, "compose_padded" },
- { V4L2_SEL_TGT_NATIVE_SIZE, "native_size" },
- { 0, nullptr }
+static constexpr std::array<flag_def, 8> selection_targets_def{
+ flag_def{ V4L2_SEL_TGT_CROP_ACTIVE, "crop" },
+ flag_def{ V4L2_SEL_TGT_CROP_DEFAULT, "crop_default" },
+ flag_def{ V4L2_SEL_TGT_CROP_BOUNDS, "crop_bounds" },
+ flag_def{ V4L2_SEL_TGT_COMPOSE_ACTIVE, "compose" },
+ flag_def{ V4L2_SEL_TGT_COMPOSE_DEFAULT, "compose_default" },
+ flag_def{ V4L2_SEL_TGT_COMPOSE_BOUNDS, "compose_bounds" },
+ flag_def{ V4L2_SEL_TGT_COMPOSE_PADDED, "compose_padded" },
+ flag_def{ V4L2_SEL_TGT_NATIVE_SIZE, "native_size" },
};
bool valid_seltarget_at_idx(unsigned i)
{
- return i < sizeof(selection_targets_def) / sizeof(selection_targets_def[0]) - 1;
+ return i < selection_targets_def.size();
}
unsigned seltarget_at_idx(unsigned i)
@@ -437,13 +438,9 @@ unsigned seltarget_at_idx(unsigned i)
std::string seltarget2s(__u32 target)
{
- int i = 0;
-
- while (selection_targets_def[i].str != nullptr) {
- if (selection_targets_def[i].flag == target)
- return selection_targets_def[i].str;
- i++;
- }
+ for (const auto &def : selection_targets_def)
+ if (def.flag == target)
+ return def.str;
return std::string("Unknown (") + num2s(target) + ")";
}
--
2.30.2
next prev parent reply other threads:[~2021-04-21 7:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-21 7:20 [PATCH 1/8] clang-tidy: use auto Rosen Penev
2021-04-21 7:20 ` [PATCH 2/8] clang-tidy: use nullptr Rosen Penev
2021-04-21 7:20 ` [PATCH 3/8] remove unused ARRAY_SIZE Rosen Penev
2021-04-21 7:20 ` [PATCH 4/8] cec-tuner: std::array conversions Rosen Penev
2021-04-21 7:20 ` Rosen Penev [this message]
2021-04-21 8:23 ` [PATCH 5/8] v4l2-info: remove a strange sizeof usage Hans Verkuil
2021-04-21 9:19 ` Rosen Penev
2021-04-21 9:33 ` Hans Verkuil
2021-04-21 9:39 ` Rosen Penev
2021-04-21 16:01 ` Nicolas Dufresne
2021-04-21 7:20 ` [PATCH 6/8] v4l2-utils: turn fb_formats to constexpr array Rosen Penev
2021-04-21 7:20 ` [PATCH 7/8] v4l2-utils: turn mbus_names into const vector Rosen Penev
2021-04-21 8:02 ` Hans Verkuil
2021-04-21 9:25 ` Rosen Penev
2021-04-21 7:20 ` [PATCH 8/8] v4l2-utils: turn prefixes to a constexpr array Rosen Penev
2021-04-21 8:06 ` Hans Verkuil
2021-04-21 9:23 ` Rosen Penev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210421072035.4188497-5-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).