bug-gzip
[Top][All Lists]
Advanced

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

Re: C99ism in gzip 1.4 inflate.c


From: Paul Eggert
Subject: Re: C99ism in gzip 1.4 inflate.c
Date: Mon, 19 Jul 2010 10:28:21 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5

For many (most?) packages we assume C99, but gzip may be an exception,
as the code is so old and crufty (some of it uses pre-C89 notation!)
and this is the only part of it that uses C99 and we perhaps should
throw all this stuff out and replace it with calls to zlib and in the
meantime it's just as easy to avoid C99.

Also, while looking at this part of the code, I noticed that it still
has an ancient coding misunderstanding (dating back to 1993!), which
I fixed while I was in the neighborhood.  Another argument for zlib,
I suppose....

>From 839ae7c3405b102a3983ed458112e2fd3c2efb4a Mon Sep 17 00:00:00 2001
From: Paul R. Eggert <address@hidden>
Date: Mon, 19 Jul 2010 10:22:10 -0700
Subject: [PATCH] gzip: don't assume C99, and don't assume overlapping memcpy 
should work

* tailor.h (NOMEMCPY): Remove.  memcpy is entitled to not work
on overlapping blocks.
* inflate.c (inflate_codes): Don't put decl after statement.
Omit NOMEMCPY.
---
 inflate.c |    7 +++----
 tailor.h  |    4 ----
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/inflate.c b/inflate.c
index 5f2f303..012bcb9 100644
--- a/inflate.c
+++ b/inflate.c
@@ -588,16 +588,15 @@ int bl, bd;             /* number of bits decoded by tl[] 
and td[] */
       /* do the copy */
       do {
         n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
-#if !defined(NOMEMCPY) && !defined(DEBUG)
-        unsigned int delta = w > d ? w - d : d - w;
-        if (delta >= e)
+#ifndef DEBUG
+        if (e <= (d < w ? w - d : d - w))
         {
           memcpy(slide + w, slide + d, e);
           w += e;
           d += e;
         }
         else                      /* do it slow to avoid memcpy() overlap */
-#endif /* !NOMEMCPY */
+#endif
           do {
             slide[w++] = slide[d++];
             Tracevv((stderr, "%c", slide[w-1]));
diff --git a/tailor.h b/tailor.h
index 4fe0da0..cc150ef 100644
--- a/tailor.h
+++ b/tailor.h
@@ -227,10 +227,6 @@
 #  endif
 #endif
 
-#if defined(pyr) && !defined(NOMEMCPY) /* Pyramid */
-#  define NOMEMCPY /* problem with overlapping copies */
-#endif
-
 #ifdef TOPS20
 #  define OS_CODE  0x0a
 #endif
-- 
1.7.1





reply via email to

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