* [PATCH] memmem.c and strstr.c: do not require -std=c99
@ 2019-08-13 0:00 Giacomo Tesio
2019-08-14 8:42 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Giacomo Tesio @ 2019-08-13 0:00 UTC (permalink / raw)
To: newlib
---
newlib/libc/string/memmem.c | 3 ++-
newlib/libc/string/strstr.c | 12 ++++++++----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/newlib/libc/string/memmem.c b/newlib/libc/string/memmem.c
index 55d2459aa..65267b9c5 100644
--- a/newlib/libc/string/memmem.c
+++ b/newlib/libc/string/memmem.c
@@ -143,10 +143,11 @@ memmem (const void *haystack, size_t hs_len,
const void *needle, size_t ne_len)
size_t tmp, shift1;
size_t m1 = ne_len - 1;
size_t offset = 0;
+ int i;
/* Initialize bad character shift hash table. */
memset (shift, 0, sizeof (shift));
- for (int i = 1; i < m1; i++)
+ for (i = 1; i < m1; i++)
shift[hash2 (ne + i)] = i;
shift1 = m1 - shift[hash2 (ne + m1)];
shift[hash2 (ne + m1)] = m1;
diff --git a/newlib/libc/string/strstr.c b/newlib/libc/string/strstr.c
index 0256c1aa6..00fe060e9 100644
--- a/newlib/libc/string/strstr.c
+++ b/newlib/libc/string/strstr.c
@@ -102,7 +102,8 @@ strstr2 (const unsigned char *hs, const unsigned char *ne)
{
uint32_t h1 = (ne[0] << 16) | ne[1];
uint32_t h2 = 0;
- for (int c = hs[0]; h1 != h2 && c != 0; c = *++hs)
+ int c;
+ for (c = hs[0]; h1 != h2 && c != 0; c = *++hs)
h2 = (h2 << 16) | c;
return h1 == h2 ? (char *)hs - 2 : NULL;
}
@@ -112,7 +113,8 @@ strstr3 (const unsigned char *hs, const unsigned char *ne)
{
uint32_t h1 = (ne[0] << 24) | (ne[1] << 16) | (ne[2] << 8);
uint32_t h2 = 0;
- for (int c = hs[0]; h1 != h2 && c != 0; c = *++hs)
+ int c;
+ for (c = hs[0]; h1 != h2 && c != 0; c = *++hs)
h2 = (h2 | c) << 8;
return h1 == h2 ? (char *)hs - 3 : NULL;
}
@@ -122,7 +124,8 @@ strstr4 (const unsigned char *hs, const unsigned char *ne)
{
uint32_t h1 = (ne[0] << 24) | (ne[1] << 16) | (ne[2] << 8) | ne[3];
uint32_t h2 = 0;
- for (int c = hs[0]; c != 0 && h1 != h2; c = *++hs)
+ int c;
+ for (c = hs[0]; c != 0 && h1 != h2; c = *++hs)
h2 = (h2 << 8) | c;
return h1 == h2 ? (char *)hs - 4 : NULL;
}
@@ -142,6 +145,7 @@ strstr (const char *haystack, const char *needle)
{
const unsigned char *hs = (const unsigned char *) haystack;
const unsigned char *ne = (const unsigned char *) needle;
+ int i;
/* Handle short needle special cases first. */
if (ne[0] == '\0')
@@ -170,7 +174,7 @@ strstr (const char *haystack, const char *needle)
/* Initialize bad character shift hash table. */
memset (shift, ne_len + 1, sizeof (shift));
- for (int i = 0; i < ne_len; i++)
+ for (i = 0; i < ne_len; i++)
shift[ne[i] % sizeof (shift)] = ne_len - i;
do
--
2.11.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] memmem.c and strstr.c: do not require -std=c99
2019-08-13 0:00 [PATCH] memmem.c and strstr.c: do not require -std=c99 Giacomo Tesio
@ 2019-08-14 8:42 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2019-08-14 8:42 UTC (permalink / raw)
To: Giacomo Tesio; +Cc: newlib
[-- Attachment #1: Type: text/plain, Size: 958 bytes --]
On Aug 13 02:00, Giacomo Tesio wrote:
> ---
> newlib/libc/string/memmem.c | 3 ++-
> newlib/libc/string/strstr.c | 12 ++++++++----
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/newlib/libc/string/memmem.c b/newlib/libc/string/memmem.c
> index 55d2459aa..65267b9c5 100644
> --- a/newlib/libc/string/memmem.c
> +++ b/newlib/libc/string/memmem.c
> @@ -143,10 +143,11 @@ memmem (const void *haystack, size_t hs_len,
> const void *needle, size_t ne_len)
> size_t tmp, shift1;
> size_t m1 = ne_len - 1;
> size_t offset = 0;
> + int i;
>
> /* Initialize bad character shift hash table. */
> memset (shift, 0, sizeof (shift));
> - for (int i = 1; i < m1; i++)
> + for (i = 1; i < m1; i++)
> shift[hash2 (ne + i)] = i;
> shift1 = m1 - shift[hash2 (ne + m1)];
> shift[hash2 (ne + m1)] = m1;
> [...]
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-14 8:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13 0:00 [PATCH] memmem.c and strstr.c: do not require -std=c99 Giacomo Tesio
2019-08-14 8:42 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).