From 04e5d8a8c1f4580b4b446d6430028d1595335617 Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 12 Dec 2013 23:42:43 +0200 Subject: [PATCH] libha: cosmetix, more comments --- src/libha.c | 14 +++++++++----- src/libha.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libha.c b/src/libha.c index 32ee3cd..4e5494d 100644 --- a/src/libha.c +++ b/src/libha.c @@ -99,10 +99,14 @@ typedef struct { /******************************************************************************/ static inline int get_byte (io_t *io) { if (io->bufin_pos >= io->bufin_max) { - io->bufin_pos = 0; - io->bufin_max = io->io->bread(io->bufin, io->bufin_size, io->udata); - if (io->bufin_max < 0) longjmp(io->errJP, LIBHA_ERR_READ); - if (io->bufin_max == 0) return -1; /* EOF */ + if (io->bufin_pos < io->bufin_size+1) { + io->bufin_pos = 0; + io->bufin_max = io->io->bread(io->bufin, io->bufin_size, io->udata); + if (io->bufin_max < 0) longjmp(io->errJP, LIBHA_ERR_READ); + if (io->bufin_max == 0) { io->bufin_pos = io->bufin_size+42; return -1; } /* EOF */ + } else { + return -1; /* EOF */ + } } return io->bufin[io->bufin_pos++]; } @@ -662,7 +666,7 @@ int libha_pack (libha_t asc) { swd_init(&asc->swd); swd_first_bytes(&asc->swd); pack_init(asc); - for (swd_findbest(&asc->swd); asc->swd.swd_char >= 0;) { + for (swd_findbest(&asc->swd); asc->swd.swd_char >= 0; ) { if (asc->swd.swd_mlf > MINLEN || (asc->swd.swd_mlf == MINLEN && asc->swd.swd_bpos < MINLENLIM)) { omlf = asc->swd.swd_mlf; obpos = asc->swd.swd_bpos; diff --git a/src/libha.h b/src/libha.h index 2ede215..1809ddf 100644 --- a/src/libha.h +++ b/src/libha.h @@ -36,7 +36,7 @@ enum { /******************************************************************************/ typedef struct libha_io_s { - int (*bread) (void *buf, int buf_len, void *udata); /* return number of bytes read; 0: EOF; <0: error */ + int (*bread) (void *buf, int buf_len, void *udata); /* return number of bytes read; 0: EOF; <0: error; can be less than buf_len */ int (*bwrite) (const void *buf, int buf_len, void *udata); /* result != buf_len: error */ } libha_io_t; -- 2.11.4.GIT