mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <jesper.juhl@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Roman Zippel <zippel@linux-m68k.org>, Petr Baudis <pasky@ucw.cz>,
	Arnaldo Carvalho de Melo <acme@conectiva.com.br>,
	Sam Ravnborg <sam@ravnborg.org>,
	Jesper Juhl <jesper.juhl@gmail.com>
Subject: [PATCH] a few small mconf improvements
Date: Sun, 7 May 2006 17:49:28 +0200	[thread overview]
Message-ID: <200605071749.28822.jesper.juhl@gmail.com> (raw)

Hi,

I just took a look at scripts/kconfig/mconf.c and found a few tiny things 
that I feel could be improved. So below is a patch for those.

The patch makes the following changes : 

 - use EXIT_SUCCESS/EXIT_FAILURE in place of 0/1.

 - rename main() arguments from "ac"/"av" to the more common "argc"/"argv".

 - when unlinking lxdialog.scrltmp, the return value of unlink() is not 
   checked. The patch adds a check of the return value and bails out if 
   unlink() fails for any reason other than ENOENT.

 - if the sscanf() call in conf() fails and stat==0 && type=='t', then 
   we'll end up dereferencing a NULL 'sym' in sym_is_choice(). The patch 
   adds a NULL check of 'sym' to that path and bails out with a big fat 
   error message if that should ever happen (better than just crashing 
   IMHO).

 - change the type if the 'i' variable in conf() from 'int' to 
   'unsigned int' to avoid a "comparison between signed and unsigned" 
   warning if building with gcc -W. Given the use of 'i', 'unsigned' is 
   also the logical type to use.

Please consider for inclusion.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

 scripts/kconfig/mconf.c |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

--- linux-2.6.17-rc3-git12-orig/scripts/kconfig/mconf.c	2006-03-20 06:53:29.000000000 +0100
+++ linux-2.6.17-rc3-git12/scripts/kconfig/mconf.c	2006-05-07 17:34:47.000000000 +0200
@@ -311,7 +311,7 @@ static void init_wsize(void)
 	if (rows < 19 || cols < 80) {
 		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
 		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	rows -= 4;
@@ -505,7 +505,7 @@ static int exec_conf(void)
 	}
 	if (WIFSIGNALED(stat)) {
 		printf("\finterrupted(%d)\n", WTERMSIG(stat));
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 #if 0
 	printf("\fexit state: %d\nexit data: '%s'\n", WEXITSTATUS(stat), input_buf);
@@ -514,7 +514,7 @@ static int exec_conf(void)
 	sigpending(&sset);
 	if (sigismember(&sset, SIGINT)) {
 		printf("\finterrupted\n");
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 	sigprocmask(SIG_SETMASK, &osset, NULL);
 
@@ -718,9 +718,14 @@ static void conf(struct menu *menu)
 	const char *prompt = menu_get_prompt(menu);
 	struct symbol *sym;
 	char active_entry[40];
-	int stat, type, i;
+	int stat, type;
+	unsigned int i;
 
-	unlink("lxdialog.scrltmp");
+	if (unlink("lxdialog.scrltmp") == -1 && errno != ENOENT) {
+		fprintf(stderr, "mconf error, unable to unlink "
+			"lxdialog.scrltmp : %s\n", strerror(errno));
+		exit(EXIT_FAILURE);
+	}
 	active_entry[0] = 0;
 	while (1) {
 		cprint_init();
@@ -777,6 +782,12 @@ static void conf(struct menu *menu)
 					conf(submenu);
 				break;
 			case 't':
+				if (!sym) {
+					fprintf(stderr, "mconf error: "
+						"expected a symbol, got NULL."
+						" Something's badly broken\n");
+					exit(EXIT_FAILURE);
+				}
 				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
 					conf_choice(submenu);
 				else if (submenu->prompt->type == P_MENU)
@@ -1038,7 +1049,7 @@ static void conf_cleanup(void)
 	unlink("lxdialog.scrltmp");
 }
 
-int main(int ac, char **av)
+int main(int argc, char **argv)
 {
 	struct symbol *sym;
 	char *mode;
@@ -1048,7 +1059,7 @@ int main(int ac, char **av)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	conf_parse(av[1]);
+	conf_parse(argv[1]);
 	conf_read(NULL);
 
 	sym = sym_lookup("KERNELVERSION", 0);
@@ -1094,5 +1105,5 @@ int main(int ac, char **av)
 			"\n\n"));
 	}
 
-	return 0;
+	return EXIT_SUCCESS;
 }



             reply	other threads:[~2006-05-07 15:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-07 15:49 Jesper Juhl [this message]
2006-05-08 22:06 ` Roman Zippel
2006-05-13 20:59   ` Jesper Juhl
2006-05-27 23:50     ` Roman Zippel

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=200605071749.28822.jesper.juhl@gmail.com \
    --to=jesper.juhl@gmail.com \
    --cc=acme@conectiva.com.br \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pasky@ucw.cz \
    --cc=sam@ravnborg.org \
    --cc=zippel@linux-m68k.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

Powered by JetHome