Skip to content

Commit

Permalink
Consuming empty messages caused fatal error (issue #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Mar 6, 2015
1 parent 74a2c82 commit 14c7bc5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kafkacat.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ static void consume_cb (rd_kafka_message_t *rkmessage, void *opaque) {
(int)rkmessage->key_len, (const char *)rkmessage->key,
conf.key_delim);

if (fwrite(rkmessage->payload, rkmessage->len, 1, fp) != 1 ||
if ((rkmessage->len > 0 &&
fwrite(rkmessage->payload, rkmessage->len, 1, fp) != 1) ||
fwrite(&conf.delim, 1, 1, fp) != 1)
FATAL("Write error for message "
"of %zd bytes at offset %"PRId64"): %s",
Expand Down Expand Up @@ -670,7 +671,7 @@ static void __attribute__((noreturn)) usage (const char *argv0, int exitcode,
" -z snappy|gzip Message compression. Default: none\n"
" -p -1 Use random partitioner\n"
" -D <delim> Delimiter to split input into messages\n"
" -K <delim> Parse key prefix for producing.\n"
" -K <delim> Delimiter to split input key and message\n"
" -T Output sent messages to stdout, acting like tee.\n"
" -c <cnt> Exit after producing this number "
"of messages\n"
Expand Down

0 comments on commit 14c7bc5

Please sign in to comment.