summaryrefslogtreecommitdiff
path: root/ext/File-Glob
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2013-11-13 12:33:40 +0000
committerDavid Mitchell <davem@iabyn.com>2013-11-13 17:38:43 +0000
commit46a847d35219c7d246a7d6498769055e62afb5f3 (patch)
tree26bcb8729dee115f402400aa18a0fa64f95df695 /ext/File-Glob
parentd07a6502d4984bc102004bf38b3a4a03cdcef346 (diff)
downloadperl-46a847d35219c7d246a7d6498769055e62afb5f3.tar.gz
File::Glob: silence some compiler warnings
In bsd_glob.c, there are nested set of functions glob0(), glob1() etc, which among their parameters pass a pointer to a compiled pattern, and also to its end. It turns out the end pointer isn't usually used, since the pattern is usually scanned for BG_EOS instead. Also, glob3() is passed two pattern ranges, both within the same pattern, and both with the same pointer to the end of the pattern buffer. Since both end pointers are the same, eliminate one of them. This removed an unused var compiler warning. Use the remaining end pointer in the glob*() functions to add assertions that we haven't fallen off the end of the buffer. Finally, ARG_MAX may be signed.
Diffstat (limited to 'ext/File-Glob')
-rw-r--r--ext/File-Glob/bsd_glob.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/ext/File-Glob/bsd_glob.c b/ext/File-Glob/bsd_glob.c
index 7ec24df664..8090b194ae 100644
--- a/ext/File-Glob/bsd_glob.c
+++ b/ext/File-Glob/bsd_glob.c
@@ -171,7 +171,7 @@ static int glob0(const Char *, glob_t *);
static int glob1(Char *, Char *, glob_t *, size_t *);
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
glob_t *, size_t *);
-static int glob3(Char *, Char *, Char *, Char *, Char *, Char *,
+static int glob3(Char *, Char *, Char *, Char *, Char *,
Char *, Char *, glob_t *, size_t *);
static int globextend(const Char *, glob_t *, size_t *);
static const Char *
@@ -639,6 +639,8 @@ glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp)
{
Char pathbuf[MAXPATHLEN];
+ assert(pattern < pattern_last);
+
/* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
if (*pattern == BG_EOS)
return(0);
@@ -660,6 +662,8 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Char *p, *q;
int anymeta;
+ assert(pattern < pattern_last);
+
/*
* Loop over pattern segments until end of pattern or until
* segment with meta character found.
@@ -699,6 +703,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
&& *p != BG_SEP2
#endif
) {
+ assert(p < pattern_last);
if (ismeta(*p))
anymeta = 1;
if (q+1 > pathend_last)
@@ -714,6 +719,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
|| *pattern == BG_SEP2
#endif
) {
+ assert(p < pattern_last);
if (pathend+1 > pathend_last)
return (1);
*pathend++ = *pattern++;
@@ -721,7 +727,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
} else
/* Need expansion, recurse. */
return(glob3(pathbuf, pathbuf_last, pathend,
- pathend_last, pattern, pattern_last,
+ pathend_last, pattern,
p, pattern_last, pglob, limitp));
}
/* NOTREACHED */
@@ -729,7 +735,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
static int
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
- Char *pattern, Char *pattern_last,
+ Char *pattern,
Char *restpattern, Char *restpattern_last, glob_t *pglob, size_t *limitp)
{
Direntry_t *dp;
@@ -738,6 +744,9 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
int nocase;
char buf[MAXPATHLEN];
+ assert(pattern < restpattern_last);
+ assert(restpattern < restpattern_last);
+
/*
* The readdirfunc declaration can't be prototyped, because it is
* assigned, below, to two functions which are prototyped in glob.h
@@ -889,7 +898,7 @@ globextend(const Char *path, glob_t *pglob, size_t *limitp)
pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
if ((pglob->gl_flags & GLOB_LIMIT) &&
- newsize + *limitp >= ARG_MAX) {
+ newsize + *limitp >= (unsigned long)ARG_MAX) {
errno = 0;
return(GLOB_NOSPACE);
}