summaryrefslogtreecommitdiff
path: root/gzread.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:27:26 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:27:26 -0700
commit7751bd4c715ea8478113e34b49b5a794a4642e8e (patch)
tree537ba82b3780f933c2f17028febd6fe3a2332190 /gzread.c
parente0ff940e1adb68d3575705ebf1546d9f07ad3b4a (diff)
downloadzlib-7751bd4c715ea8478113e34b49b5a794a4642e8e.tar.gz
zlib 1.2.3.9v1.2.3.9
Diffstat (limited to 'gzread.c')
-rw-r--r--gzread.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/gzread.c b/gzread.c
index a560c16..7f68055 100644
--- a/gzread.c
+++ b/gzread.c
@@ -3,8 +3,6 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-#ifndef OLD_GZIO
-
#include "gzguts.h"
/* Local functions */
@@ -547,8 +545,8 @@ char * ZEXPORT gzgets(file, buf, len)
unsigned char *eol;
gz_statep state;
- /* get internal structure */
- if (file == NULL)
+ /* check parameters and get internal structure */
+ if (file == NULL || buf == NULL || len < 1)
return NULL;
state = (gz_statep)file;
@@ -563,16 +561,12 @@ char * ZEXPORT gzgets(file, buf, len)
return NULL;
}
- /* check for a dumb length */
- if (len < 2)
- return NULL;
-
/* copy output bytes up to new line or len - 1, whichever comes first --
append a terminating zero to the string (we don't check for a zero in
the contents, let the user worry about that) */
str = buf;
left = (unsigned)len - 1;
- do {
+ if (left) do {
/* assure that something is in the output buffer */
if (state->have == 0) {
if (gz_make(state) == -1)
@@ -588,7 +582,7 @@ char * ZEXPORT gzgets(file, buf, len)
n = state->have > left ? left : state->have;
eol = memchr(state->next, '\n', n);
if (eol != NULL)
- n = (eol - state->next) + 1;
+ n = (unsigned)(eol - state->next) + 1;
/* copy through end-of-line, or remainder if not found */
memcpy(buf, state->next, n);
@@ -655,5 +649,3 @@ int ZEXPORT gzclose_r(file)
free(state);
return ret ? Z_ERRNO : Z_OK;
}
-
-#endif /* !OLD_GZIO */