diff options
author | Petr Machata <pmachata@redhat.com> | 2013-01-09 22:23:23 +0100 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2013-03-08 22:56:12 +0100 |
commit | 5ca9b6fb48aaaefdf34039d32267a02e76f4ceb8 (patch) | |
tree | d5128f7d83bc36966da9a77b5edd98f5591c20ad /glob.c | |
parent | aeb549016d8f536ca007ff0943f9583389dff121 (diff) | |
download | ltrace-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.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -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 |