Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ldpd fix uninitialized variable by elimination.
details: https://anonhg.NetBSD.org/src/rev/e07f0fcaa2d6
branches: trunk
changeset: 759677:e07f0fcaa2d6
user: christos <christos%NetBSD.org@localhost>
date: Tue Dec 14 21:32:43 2010 +0000
description:
fix uninitialized variable by elimination.
diffstat:
usr.sbin/ldpd/ldp_command.c | 56 ++++++++++++++++++++++++--------------------
1 files changed, 30 insertions(+), 26 deletions(-)
diffs (82 lines):
diff -r 4cf6a80d8a9a -r e07f0fcaa2d6 usr.sbin/ldpd/ldp_command.c
--- a/usr.sbin/ldpd/ldp_command.c Tue Dec 14 20:45:22 2010 +0000
+++ b/usr.sbin/ldpd/ldp_command.c Tue Dec 14 21:32:43 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_command.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */
+/* $NetBSD: ldp_command.c,v 1.2 2010/12/14 21:32:43 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -284,43 +284,47 @@
int
command_match(struct com_func *cf, int s, char *orig, char *next)
{
- int i, matched = 0, last_match;
+ size_t i, len;
+ int last_match = -1;
+ const char *msg = NULL;
- if (orig == NULL || orig[0] == '\0') {
- send_prompt(s);
- return 0;
- }
+ if (orig == NULL || orig[0] == '\0')
+ goto out;
if (!strcmp(orig, "?")) {
- for (i=0; cf[i].func != NULL; i++) {
+ for (i = 0; cf[i].func != NULL; i++) {
snprintf(sendspace, MAXSEND, "\t%s\n", cf[i].com);
writestr(s, sendspace);
}
- send_prompt(s);
- return 0;
+ goto out;
+ }
+
+ len = strlen(orig);
+ for (i = 0; cf[i].func != NULL; i++) {
+ if (strncasecmp(orig, cf[i].com, len) == 0) {
+ if (last_match != -1) {
+ msg = "Ambiguous";
+ goto out;
+ } else
+ last_match = i;
+ }
}
- for (i=0; cf[i].func != NULL; i++)
- if(strncasecmp(orig, cf[i].com, strlen(orig)) == 0) {
- matched++;
- last_match = i;
- }
- if (!matched) {
- writestr(s, "Unknown command. Use ? for help\n");
- send_prompt(s);
- return 0;
+ if (last_match == -1) {
+ msg = "Unknown";
+ goto out;
}
- if (matched > 1) {
- writestr(s, "Ambiguous command. Use ? for help\n");
- send_prompt(s);
- return 0;
- }
-
- if(cf[last_match].func(s, next) != 0)
+ if (cf[last_match].func(s, next) != 0)
send_prompt(s);
return 1;
-
+out:
+ if (msg) {
+ writestr(s, msg);
+ writestr(s, " command. Use ? for help\n");
+ }
+ send_prompt(s);
+ return 0;
}
/*
Home |
Main Index |
Thread Index |
Old Index