Skip to content

Commit 24a489a

Browse files
committed
Release k8-0.2.5 (r80)
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.
1 parent e2e1c84 commit 24a489a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

k8.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
SOFTWARE.
2424
*/
25-
#define K8_VERSION "0.2.4-r79" // known to work with V8-3.16.14
25+
#define K8_VERSION "0.2.5-r80" // known to work with V8-3.16.14
2626

2727
#include <stdlib.h>
2828
#include <stdint.h>
@@ -454,6 +454,7 @@ static size_t ks_read(file_t &fp, kstream_t *ks, uint8_t *buf, long len, reader_
454454
template<typename file_t, typename reader_t>
455455
static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, int *dret, int offset, reader_t reader)
456456
{
457+
int gotany = 0;
457458
if (dret) *dret = 0;
458459
kv->n = offset >= 0? offset : 0;
459460
if (ks->begin >= ks->end && ks->is_eof) return -1;
@@ -463,8 +464,8 @@ static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, in
463464
if (!ks->is_eof) {
464465
ks->begin = 0;
465466
ks->end = reader(fp, ks->buf, ks->buf_size);
466-
if (ks->end < ks->buf_size) ks->is_eof = 1;
467-
if (ks->end == 0) break;
467+
if (ks->end == 0) { ks->is_eof = 1; break; }
468+
if (ks->end < 0) { ks->is_eof = 1; return -3; }
468469
} else break;
469470
}
470471
if (delimiter == KS_SEP_LINE) {
@@ -485,6 +486,7 @@ static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, in
485486
kroundup32(kv->m);
486487
kv->a = (uint8_t*)realloc(kv->a, kv->m);
487488
}
489+
gotany = 1;
488490
memcpy(kv->a + kv->n, ks->buf + ks->begin, i - ks->begin);
489491
kv->n = kv->n + (i - ks->begin);
490492
ks->begin = i + 1;
@@ -493,6 +495,7 @@ static int ks_getuntil(file_t &fp, kstream_t *ks, kvec8_t *kv, int delimiter, in
493495
break;
494496
}
495497
}
498+
if (!gotany && ks_eof(ks)) return -1;
496499
if (kv->a == 0) {
497500
kv->m = 1;
498501
kv->a = (uint8_t*)calloc(1, 1);

0 commit comments

Comments
 (0)