summaryrefslogtreecommitdiff
path: root/src/kwset.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-03-27 10:01:40 +0100
committerJim Meyering <meyering@redhat.com>2010-03-27 10:47:57 +0100
commitc03209e3bb4a64a4ceacf3c02e6ba69cb1457d4d (patch)
treecec721649a2158f89c0510581009beb4e26cd7e2 /src/kwset.c
parentef5011d294a4dfc21a726b3103e9d277912cabaf (diff)
downloadgrep-c03209e3bb4a64a4ceacf3c02e6ba69cb1457d4d.tar.gz
kwset: correct comments; require non-NULL kwsmatch argument
* src/kwset.c (kwsexec): Correct comments. This function has been returning an offset, not a pointer, for 9 years. Do not test for kwsmatch == NULL. All callers pass non-NULL. (cwexec): Likewise. * src/kwset.h (kwsexec): Mark the 4th parameter, kwsmatch, as non-NULL. Include "arg-nonnull.h".
Diffstat (limited to 'src/kwset.c')
-rw-r--r--src/kwset.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/kwset.c b/src/kwset.c
index 9e3a6755..050562ef 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -583,7 +583,7 @@ bmexec (kwset_t kws, char const *text, size_t size)
}
/* Hairy multiple string search. */
-static size_t
+static size_t _GL_ARG_NONNULL ((4))
cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
{
struct kwset const *kwset;
@@ -731,31 +731,26 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
d = 1;
}
- if (kwsmatch)
- {
- kwsmatch->index = accept->accepting / 2;
- kwsmatch->offset[0] = mch - text;
- kwsmatch->size[0] = accept->depth;
- }
+ kwsmatch->index = accept->accepting / 2;
+ kwsmatch->offset[0] = mch - text;
+ kwsmatch->size[0] = accept->depth;
+
return mch - text;
}
-/* Search through the given text for a match of any member of the
- given keyword set. Return a pointer to the first character of
- the matching substring, or NULL if no match is found. If FOUNDLEN
- is non-NULL store in the referenced location the length of the
- matching substring. Similarly, if FOUNDIDX is non-NULL, store
- in the referenced location the index number of the particular
- keyword matched. */
+/* Search TEXT for a match of any member of the keyword set, KWS.
+ Return the offset (into TEXT) of the first byte of the matching substring,
+ or (size_t) -1 if no match is found. Upon a match, store details in
+ *KWSMATCH: index of matched keyword, start offset (same as the return
+ value), and length. */
size_t
-kwsexec (kwset_t kws, char const *text, size_t size,
- struct kwsmatch *kwsmatch)
+kwsexec (kwset_t kws, char const *text, size_t size, struct kwsmatch *kwsmatch)
{
struct kwset const *kwset = (struct kwset *) kws;
if (kwset->words == 1 && kwset->trans == NULL)
{
size_t ret = bmexec (kws, text, size);
- if (kwsmatch != NULL && ret != (size_t) -1)
+ if (ret != (size_t) -1)
{
kwsmatch->index = 0;
kwsmatch->offset[0] = ret;