aboutsummaryrefslogtreecommitdiff
path: root/glob.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2013-01-09 22:23:23 +0100
committerPetr Machata <pmachata@redhat.com>2013-03-08 22:56:12 +0100
commit5ca9b6fb48aaaefdf34039d32267a02e76f4ceb8 (patch)
treed5128f7d83bc36966da9a77b5edd98f5591c20ad /glob.c
parentaeb549016d8f536ca007ff0943f9583389dff121 (diff)
downloadltrace-5ca9b6fb48aaaefdf34039d32267a02e76f4ceb8.tar.gz
Replace one manual loop in glob.c with a call to memchr
- In the process, get rid of use of uninitialized i for cases that length is 0. Since length should be > 0 anyway in that code, add an assert covering that.
Diffstat (limited to 'glob.c')
-rw-r--r--glob.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/glob.c b/glob.c
index c497b3c..4f826c7 100644
--- a/glob.c
+++ b/glob.c
@@ -27,13 +27,11 @@
static ssize_t
match_character_class(const char *glob, size_t length, size_t from)
{
- size_t i = 0;
- if (length > 0)
- for (i = from + 2; i < length - 1 && glob[++i] != ':'; )
- ;
- if (i >= length || glob[++i] != ']')
+ assert(length > 0);
+ const char *colon = memchr(glob + from + 2, ':', length - 1);
+ if (colon == NULL || colon[1] != ']')
return -1;
- return i;
+ return colon - glob;
}
static ssize_t