aboutsummaryrefslogtreecommitdiff
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-7751bd4c715ea8478113e34b49b5a794a4642e8e.tar.bz2
zlib-7751bd4c715ea8478113e34b49b5a794a4642e8e.zip
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 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6#ifndef OLD_GZIO
7
8#include "gzguts.h" 6#include "gzguts.h"
9 7
10/* Local functions */ 8/* Local functions */
@@ -547,8 +545,8 @@ char * ZEXPORT gzgets(file, buf, len)
547 unsigned char *eol; 545 unsigned char *eol;
548 gz_statep state; 546 gz_statep state;
549 547
550 /* get internal structure */ 548 /* check parameters and get internal structure */
551 if (file == NULL) 549 if (file == NULL || buf == NULL || len < 1)
552 return NULL; 550 return NULL;
553 state = (gz_statep)file; 551 state = (gz_statep)file;
554 552
@@ -563,16 +561,12 @@ char * ZEXPORT gzgets(file, buf, len)
563 return NULL; 561 return NULL;
564 } 562 }
565 563
566 /* check for a dumb length */
567 if (len < 2)
568 return NULL;
569
570 /* copy output bytes up to new line or len - 1, whichever comes first -- 564 /* copy output bytes up to new line or len - 1, whichever comes first --
571 append a terminating zero to the string (we don't check for a zero in 565 append a terminating zero to the string (we don't check for a zero in
572 the contents, let the user worry about that) */ 566 the contents, let the user worry about that) */
573 str = buf; 567 str = buf;
574 left = (unsigned)len - 1; 568 left = (unsigned)len - 1;
575 do { 569 if (left) do {
576 /* assure that something is in the output buffer */ 570 /* assure that something is in the output buffer */
577 if (state->have == 0) { 571 if (state->have == 0) {
578 if (gz_make(state) == -1) 572 if (gz_make(state) == -1)
@@ -588,7 +582,7 @@ char * ZEXPORT gzgets(file, buf, len)
588 n = state->have > left ? left : state->have; 582 n = state->have > left ? left : state->have;
589 eol = memchr(state->next, '\n', n); 583 eol = memchr(state->next, '\n', n);
590 if (eol != NULL) 584 if (eol != NULL)
591 n = (eol - state->next) + 1; 585 n = (unsigned)(eol - state->next) + 1;
592 586
593 /* copy through end-of-line, or remainder if not found */ 587 /* copy through end-of-line, or remainder if not found */
594 memcpy(buf, state->next, n); 588 memcpy(buf, state->next, n);
@@ -655,5 +649,3 @@ int ZEXPORT gzclose_r(file)
655 free(state); 649 free(state);
656 return ret ? Z_ERRNO : Z_OK; 650 return ret ? Z_ERRNO : Z_OK;
657} 651}
658
659#endif /* !OLD_GZIO */