I don't see any warnings. Please show them.
If gcc is being fooled by loops, then this is because gcc is stupid.
it you show the warnings we can judge it.
In particular, the slen one looks totally bogus.
> This diff fixes uninitialized variable warnings emitted by gcc 4.2.1
> on i386/amd64.
>
> Index: eval.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/eval.c,v
> retrieving revision 1.35
> diff -u -p -r1.35 eval.c
> --- eval.c 24 Mar 2010 08:27:26 -0000 1.35
> +++ eval.c 14 Mar 2011 03:05:10 -0000
> @@ -159,6 +159,8 @@ expand(char *cp, /* input word */
> int make_magic;
> size_t len;
>
> + x.split = 0;
> + x.str = NULL;
> if (cp == NULL)
> internal_errorf(1, "expand(NULL)");
> /* for alias, readonly, set, typeset commands */
> @@ -267,6 +269,7 @@ expand(char *cp, /* input word */
> int stype;
> int slen;
>
> + slen = -1;
> sp = strchr(sp, '\0') + 1; /* skip variable */
> type = varsub(&x, varname, sp, &stype, &slen);
> if (type < 0) {