Hi,
I was trying to figure out what get_column_format_matches was supposed
to do, and I just couldn't understand the for loop. Probably because
it's completely superfluous. Nothing in the switch depends on i, and
the if (i==format) can be gotten rid of. If format is guaranteed to
be legal, you can even get rid of the refactored if, though I didn't
do that.
Todd
diff -u -r1.30 column.c
--- column.c 2000/11/17 21:00:35 1.30
+++ column.c 2001/07/09 12:08:23
@@ -96,59 +96,57 @@
column format */
void
get_column_format_matches(gboolean *fmt_list, gint format) {
- int i;
-
- for (i = 0; i < NUM_COL_FMTS; i++) {
- /* Get the obvious: the format itself */
- if (i == format)
- fmt_list[i] = TRUE;
- /* Get any formats lower down on the chain */
- switch (format) {
- case COL_DEF_SRC:
- fmt_list[COL_RES_DL_SRC] = TRUE;
- fmt_list[COL_RES_NET_SRC] = TRUE;
- break;
- case COL_RES_SRC:
- fmt_list[COL_RES_DL_SRC] = TRUE;
- fmt_list[COL_RES_NET_SRC] = TRUE;
- break;
- case COL_UNRES_SRC:
- fmt_list[COL_UNRES_DL_SRC] = TRUE;
- fmt_list[COL_UNRES_NET_SRC] = TRUE;
- break;
- case COL_DEF_DST:
- fmt_list[COL_RES_DL_DST] = TRUE;
- fmt_list[COL_RES_NET_DST] = TRUE;
- break;
- case COL_RES_DST:
- fmt_list[COL_RES_DL_DST] = TRUE;
- fmt_list[COL_RES_NET_DST] = TRUE;
- break;
- case COL_UNRES_DST:
- fmt_list[COL_UNRES_DL_DST] = TRUE;
- fmt_list[COL_UNRES_NET_DST] = TRUE;
- break;
- case COL_DEF_DL_SRC:
- fmt_list[COL_RES_DL_SRC] = TRUE;
- break;
- case COL_DEF_DL_DST:
- fmt_list[COL_RES_DL_DST] = TRUE;
- break;
- case COL_DEF_NET_SRC:
- fmt_list[COL_RES_NET_SRC] = TRUE;
- break;
- case COL_DEF_NET_DST:
- fmt_list[COL_RES_NET_DST] = TRUE;
- break;
- case COL_DEF_SRC_PORT:
- fmt_list[COL_RES_SRC_PORT] = TRUE;
- break;
- case COL_DEF_DST_PORT:
- fmt_list[COL_RES_DST_PORT] = TRUE;
- break;
- default:
- break;
- }
+
+ /* Get the obvious: the format itself */
+ if ((format >= 0) && (format < NUM_COL_FMTS))
+ fmt_list[format] = TRUE;
+
+ /* Get any formats lower down on the chain */
+ switch (format) {
+ case COL_DEF_SRC:
+ fmt_list[COL_RES_DL_SRC] = TRUE;
+ fmt_list[COL_RES_NET_SRC] = TRUE;
+ break;
+ case COL_RES_SRC:
+ fmt_list[COL_RES_DL_SRC] = TRUE;
+ fmt_list[COL_RES_NET_SRC] = TRUE;
+ break;
+ case COL_UNRES_SRC:
+ fmt_list[COL_UNRES_DL_SRC] = TRUE;
+ fmt_list[COL_UNRES_NET_SRC] = TRUE;
+ break;
+ case COL_DEF_DST:
+ fmt_list[COL_RES_DL_DST] = TRUE;
+ fmt_list[COL_RES_NET_DST] = TRUE;
+ break;
+ case COL_RES_DST:
+ fmt_list[COL_RES_DL_DST] = TRUE;
+ fmt_list[COL_RES_NET_DST] = TRUE;
+ break;
+ case COL_UNRES_DST:
+ fmt_list[COL_UNRES_DL_DST] = TRUE;
+ fmt_list[COL_UNRES_NET_DST] = TRUE;
+ break;
+ case COL_DEF_DL_SRC:
+ fmt_list[COL_RES_DL_SRC] = TRUE;
+ break;
+ case COL_DEF_DL_DST:
+ fmt_list[COL_RES_DL_DST] = TRUE;
+ break;
+ case COL_DEF_NET_SRC:
+ fmt_list[COL_RES_NET_SRC] = TRUE;
+ break;
+ case COL_DEF_NET_DST:
+ fmt_list[COL_RES_NET_DST] = TRUE;
+ break;
+ case COL_DEF_SRC_PORT:
+ fmt_list[COL_RES_SRC_PORT] = TRUE;
+ break;
+ case COL_DEF_DST_PORT:
+ fmt_list[COL_RES_DST_PORT] = TRUE;
+ break;
+ default:
+ break;
}
}