bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_FUNC_MEMMEM


From: Eric Blake
Subject: Re: AC_FUNC_MEMMEM
Date: Tue, 08 Jan 2008 06:06:58 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[re-adding bug-gnulib; this patch does not make sense for memmem.c, since
it no longer uses knuth_morris_pratt, but might still be useful for str-kmp.h]

- -------- Original Message --------
On Tue, 2008-01-08 at 11:15 +1100, Peter Miller wrote:
| Or am I missing something subtle?

yes, I was missing something subtle.
The attached patch adds comments to explain it to me.


Regards
Peter Miller <address@hidden>
/\/\*        http://miller.emu.id.au/pmiller/

PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53  2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.

"A fanatic is a man who consciously over compensates
a secret doubt."  -- Aldous Huxley
- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHg3Vy84KuGfSFAYARAsxTAKChH+O+TYRuRQysiI0/+/DaIEPeFQCfUqYn
XtSXewa0G56QcuQ4YyS/nj4=
=b74R
-----END PGP SIGNATURE-----
--- memmem.c    2008-01-08 11:09:47.000000000 +1100
+++ new-memmem.c        2008-01-08 11:30:59.000000000 +1100
@@ -31,7 +31,9 @@
 
 /* Knuth-Morris-Pratt algorithm.
    See http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm
-   Return a boolean indicating success.  */
+   Return a boolean indicating success: false means the malloc failed,
+   true means that the comparison has been completed, and *resultp will
+   the appropriate value to return from memmem.  */
 
 static bool
 knuth_morris_pratt (const unsigned char *haystack,
@@ -148,6 +150,8 @@
   }
 
   freea (table);
+  /* The comparison has been completed, and *resultp now contains the
+     correct value to be returned from memmem.  */
   return true;
 }
 
@@ -218,7 +222,10 @@
               needle.  */
            if (comparison_count >= needle_len)
              {
-               /* Try the Knuth-Morris-Pratt algorithm.  */
+                /* Try the Knuth-Morris-Pratt algorithm.  Note that
+                   returning false means the malloc failed, and we
+                   will not try KMP again.  Returning true means that
+                   "result" contains the value to be returned my memmem.  */
                const unsigned char *result;
                if (knuth_morris_pratt (haystack, last_haystack,
                                        needle - 1, needle_len, &result))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]