tSearch signature backward from end of stream - sick - sign and check files using ed25519
(HTM) git clone git://z3bra.org/sick
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 398fc545a7d63eafa6764cf0ca320798ec3b88b3
(DIR) parent cc294e4bf70f3e2bb907a15c94b18f3535011105
(HTM) Author: z3bra <willyatmailoodotorg>
Date: Wed, 14 Sep 2016 23:52:23 +0200
Search signature backward from end of stream
Diffstat:
M sick.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/sick.c b/sick.c
t@@ -51,12 +51,14 @@ usage()
/*
* Find a string within a memory chunk, stupid style!
+ * Search is done backward, as the signature will be appended at the
+ * end of the stream.
*/
char *
memstr(const void *h0, size_t k, const char *n0, size_t l)
{
- size_t i;
- const char *h = h0;
+ ssize_t i;
+ const unsigned char *h = h0;
/* Return immediately on empty needle */
if (!l) return (char *)h;
t@@ -64,7 +66,7 @@ memstr(const void *h0, size_t k, const char *n0, size_t l)
/* Return immediately when needle is longer than haystack */
if (k<l) return 0;
- for (i=0; i<=(k-l); i++) {
+ for (i=k-l; i>0; i--) {
if (memcmp(h+i, n0, l) == 0)
return (char *)(h+i);
}