Skip to content

Commit

Permalink
Release k8-0.2.5 (r80)
Browse files Browse the repository at this point in the history
Fixed a bug in readline that reads an empty line when the file size is a
multiple of 65536. This is the same bug in klib/kseq.h.
  • Loading branch information
lh3 committed Apr 7, 2018
1 parent e2e1c84 commit 24a489a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions k8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#define K8_VERSION "0.2.4-r79" // known to work with V8-3.16.14
#define K8_VERSION "0.2.5-r80" // known to work with V8-3.16.14

#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -454,6 +454,7 @@ static size_t ks_read(file_t &fp, kstream_t *ks, uint8_t *buf, long len, reader_
template<typename file_t, typename reader_t>
static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, int *dret, int offset, reader_t reader)
{
int gotany = 0;
if (dret) *dret = 0;
kv->n = offset >= 0? offset : 0;
if (ks->begin >= ks->end && ks->is_eof) return -1;
Expand All @@ -463,8 +464,8 @@ static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, in
if (!ks->is_eof) {
ks->begin = 0;
ks->end = reader(fp, ks->buf, ks->buf_size);
if (ks->end < ks->buf_size) ks->is_eof = 1;
if (ks->end == 0) break;
if (ks->end == 0) { ks->is_eof = 1; break; }
if (ks->end < 0) { ks->is_eof = 1; return -3; }
} else break;
}
if (delimiter == KS_SEP_LINE) {
Expand All @@ -485,6 +486,7 @@ static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, in
kroundup32(kv->m);
kv->a = (uint8_t*)realloc(kv->a, kv->m);
}
gotany = 1;
memcpy(kv->a + kv->n, ks->buf + ks->begin, i - ks->begin);
kv->n = kv->n + (i - ks->begin);
ks->begin = i + 1;
Expand All @@ -493,6 +495,7 @@ static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, in
break;
}
}
if (!gotany && ks_eof(ks)) return -1;
if (kv->a == 0) {
kv->m = 1;
kv->a = (uint8_t*)calloc(1, 1);
Expand Down

0 comments on commit 24a489a

Please sign in to comment.