From 867f2c406941a0de5691b6e550dbaea0262a3429 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 5 Feb 2012 11:16:08 -0800 Subject: [PATCH] sh: Cache de->d_namlen in a local variable. Obtained-from: FreeBSD 228941 --- bin/sh/expand.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 12ac06f481..2cb334030b 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)expand.c 8.5 (Berkeley) 5/15/95 - * $FreeBSD: src/bin/sh/expand.c,v 1.91 2011/06/15 21:48:10 jilles Exp $ + * $FreeBSD: src/bin/sh/expand.c,v 1.92 2011/12/28 23:30:17 jilles Exp $ */ #include @@ -1185,6 +1185,7 @@ expmeta(char *enddir, char *name) int atend; int matchdot; int esc; + int namlen; metaflag = 0; start = name; @@ -1283,17 +1284,18 @@ expmeta(char *enddir, char *name) if (dp->d_name[0] == '.' && ! matchdot) continue; if (patmatch(start, dp->d_name, 0)) { - if (enddir + dp->d_namlen + 1 > expdir_end) + namlen = dp->d_namlen; + if (enddir + namlen + 1 > expdir_end) continue; - memcpy(enddir, dp->d_name, dp->d_namlen + 1); + memcpy(enddir, dp->d_name, namlen + 1); if (atend) addfname(expdir); else { - if (enddir + dp->d_namlen + 2 > expdir_end) + if (enddir + namlen + 2 > expdir_end) continue; - enddir[dp->d_namlen] = '/'; - enddir[dp->d_namlen + 1] = '\0'; - expmeta(enddir + dp->d_namlen + 1, endname); + enddir[namlen] = '/'; + enddir[namlen + 1] = '\0'; + expmeta(enddir + namlen + 1, endname); } } } -- 2.41.0