X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fali.c;h=880fe2123e4ddbe79216bb06d6d461bf5ad99605;hb=bfad64befb4d6696fdfb63b119666eec4bac6fb3;hp=61ab6b214f7f42a218f5ee8c30eaa53728196eb0;hpb=cff8de7654cf393a494b01a587bd4d503d15a5e3;p=mmh diff --git a/uip/ali.c b/uip/ali.c index 61ab6b2..880fe21 100644 --- a/uip/ali.c +++ b/uip/ali.c @@ -13,11 +13,6 @@ #include #include -/* - * maximum number of names - */ -#define NVEC 50 - static struct swit switches[] = { #define ALIASW 0 { "alias aliasfile", 0 }, @@ -59,7 +54,9 @@ main (int argc, char **argv) int i, vecp = 0, inverted = 0, list = 0; int noalias = 0, normalize = AD_NHST; char *cp, **ap, **argp, buf[BUFSIZ]; - char *vec[NVEC], **arguments; + /* Really only need to allocate for argc-1, but must allocate at least 1, + so go ahead and allocate for argc char pointers. */ + char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments; struct aka *ak; #ifdef LOCALE @@ -124,7 +121,14 @@ main (int argc, char **argv) continue; } } - vec[vecp++] = cp; + + if (vecp < argc) { + vec[vecp++] = cp; + } else { + /* Should never happen, but try to protect against code changes + that could allow it. */ + adios (NULL, "too many arguments"); + } } if (!noalias) { @@ -151,23 +155,22 @@ main (int argc, char **argv) for (i = 0; i < vecp; i++) print_usr (vec[i], list, normalize); - - done (0); - } - - if (vecp) { - /* print specified aliases */ - for (i = 0; i < vecp; i++) - print_aka (akvalue (vec[i]), list, 0); } else { - /* print them all */ - for (ak = akahead; ak; ak = ak->ak_next) { - printf ("%s: ", ak->ak_name); - pos += strlen (ak->ak_name) + 1; - print_aka (akresult (ak), list, pos); + if (vecp) { + /* print specified aliases */ + for (i = 0; i < vecp; i++) + print_aka (akvalue (vec[i]), list, 0); + } else { + /* print them all */ + for (ak = akahead; ak; ak = ak->ak_next) { + printf ("%s: ", ak->ak_name); + pos += strlen (ak->ak_name) + 1; + print_aka (akresult (ak), list, pos); + } } } + free (vec); done (0); return 1; } @@ -246,12 +249,7 @@ print_usr (char *s, int list, int norm) } mnfree (mp); -#if 0 - printf ("%s: ", s); - print_aka (vp ? vp : s, list, pos += strlen (s) + 1); -#else print_aka (vp ? vp : s, list, 0); -#endif if (vp) free (vp);