From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 01/15] options: let handle_onoff_switch() use null terminated arrays
Date: Sun, 5 Jul 2020 15:02:06 +0200 [thread overview]
Message-ID: <20200705130220.26230-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200705130220.26230-1-luc.vanoostenryck@gmail.com>
This makes things slightly easier to use.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
lib.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib.c b/lib.c
index e56788260cb7..709dd5176112 100644
--- a/lib.c
+++ b/lib.c
@@ -529,14 +529,14 @@ enum {
WARNING_FORCE_OFF
};
-static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[], int n)
+static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[])
{
int flag = WARNING_ON;
char *p = arg + 1;
unsigned i;
if (!strcmp(p, "sparse-all")) {
- for (i = 0; i < n; i++) {
+ for (i = 0; warnings[i].name; i++) {
if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
*warnings[i].flag = WARNING_ON;
}
@@ -551,7 +551,7 @@ static char **handle_onoff_switch(char *arg, char **next, const struct flag warn
flag = WARNING_FORCE_OFF;
}
- for (i = 0; i < n; i++) {
+ for (i = 0; warnings[i].name; i++) {
if (!strcmp(p,warnings[i].name)) {
*warnings[i].flag = flag;
return next;
@@ -789,11 +789,12 @@ static const struct flag warnings[] = {
{ "universal-initializer", &Wuniversal_initializer },
{ "unknown-attribute", &Wunknown_attribute },
{ "vla", &Wvla },
+ { }
};
static char **handle_switch_W(char *arg, char **next)
{
- char ** ret = handle_onoff_switch(arg, next, warnings, ARRAY_SIZE(warnings));
+ char ** ret = handle_onoff_switch(arg, next, warnings);
if (ret)
return ret;
@@ -808,12 +809,13 @@ static struct flag debugs[] = {
{ "entry", &dbg_entry},
{ "ir", &dbg_ir},
{ "postorder", &dbg_postorder},
+ { }
};
static char **handle_switch_v(char *arg, char **next)
{
- char ** ret = handle_onoff_switch(arg, next, debugs, ARRAY_SIZE(debugs));
+ char ** ret = handle_onoff_switch(arg, next, debugs);
if (ret)
return ret;
@@ -856,11 +858,11 @@ static char **handle_switch_d(char *arg, char **next)
}
-static void handle_onoff_switch_finalize(const struct flag warnings[], int n)
+static void handle_onoff_switch_finalize(const struct flag warnings[])
{
unsigned i;
- for (i = 0; i < n; i++) {
+ for (i = 0; warnings[i].name; i++) {
if (*warnings[i].flag == WARNING_FORCE_OFF)
*warnings[i].flag = WARNING_OFF;
}
@@ -868,7 +870,7 @@ static void handle_onoff_switch_finalize(const struct flag warnings[], int n)
static void handle_switch_W_finalize(void)
{
- handle_onoff_switch_finalize(warnings, ARRAY_SIZE(warnings));
+ handle_onoff_switch_finalize(warnings);
/* default Wdeclarationafterstatement based on the C dialect */
if (-1 == Wdeclarationafterstatement) {
@@ -886,7 +888,7 @@ static void handle_switch_W_finalize(void)
static void handle_switch_v_finalize(void)
{
- handle_onoff_switch_finalize(debugs, ARRAY_SIZE(debugs));
+ handle_onoff_switch_finalize(debugs);
}
static char **handle_switch_U(char *arg, char **next)
--
2.27.0
next prev parent reply other threads:[~2020-07-05 13:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-05 13:02 [PATCH 00/15] tidy-up options / reorganize lib.c Luc Van Oostenryck
2020-07-05 13:02 ` Luc Van Oostenryck [this message]
2020-07-05 13:02 ` [PATCH 02/15] options: move -Wsparse-all's processing out of handle_onoff_switch() Luc Van Oostenryck
2020-07-05 13:02 ` Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 03/15] options: move on top the definition of warning type enums Luc Van Oostenryck
2020-07-05 13:02 ` Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 04/15] options: make Wsparse_error less special Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 05/15] options: handle_onoff_switch() can handle any flags, not only warnings Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 06/15] options: move helpers up Luc Van Oostenryck
2020-07-05 13:02 ` Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 07/15] options: alphasort the handle_switch_[a-zA_Z]() Luc Van Oostenryck
2020-07-05 13:02 ` Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 08/15] options: avoid spaces between function name and arguments list Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 09/15] options: move declaration of tabstop out of "token.h" Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 10/15] options: add a small helper: handle_switch_finalize() Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 11/15] options: move option parsing in a separate file Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 12/15] options: keep the options sorted Luc Van Oostenryck
2020-07-05 13:02 ` Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 13/15] cleanup: move predefines in a separate file Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 14/15] cleanup: move parsing helpers to parse.c Luc Van Oostenryck
2020-07-05 17:27 ` Linus Torvalds
2020-07-05 20:45 ` Luc Van Oostenryck
2020-07-05 13:02 ` [PATCH 15/15] cleanup: move hexval() to utils.c Luc Van Oostenryck
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=20200705130220.26230-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@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