Skip to content

Commit

Permalink
global: Fixed slighty wrong i_stream_read_data() with _read_bytes()
Browse files Browse the repository at this point in the history
These calls were reading one byte more than they were intended to read.
This didn't really cause any problems, but now they're correct.
  • Loading branch information
sirainen committed May 18, 2016
1 parent 4b5a2e9 commit d868a04
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lda/main.c
Expand Up @@ -123,8 +123,8 @@ create_raw_stream(struct mail_deliver_context *ctx,
input = i_stream_create_fd(fd, 4096, FALSE);
input->blocking = TRUE;
/* If input begins with a From-line, drop it */
ret = i_stream_read_data(input, &data, &size, 5);
if (ret > 0 && size >= 5 && memcmp(data, "From ", 5) == 0) {
ret = i_stream_read_bytes(input, &data, &size, 5);
if (ret > 0 && memcmp(data, "From ", 5) == 0) {
/* skip until the first LF */
i_stream_skip(input, 5);
while (i_stream_read_more(input, &data, &size) > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib-compression/istream-lz4.c
Expand Up @@ -100,8 +100,8 @@ static ssize_t i_stream_lz4_read(struct istream_private *stream)
}

if (zstream->chunk_left == 0) {
ret = i_stream_read_data(stream->parent, &data, &size,
IOSTREAM_LZ4_CHUNK_PREFIX_LEN);
ret = i_stream_read_bytes(stream->parent, &data, &size,
IOSTREAM_LZ4_CHUNK_PREFIX_LEN);
if (ret < 0) {
stream->istream.stream_errno =
stream->parent->stream_errno;
Expand Down
4 changes: 2 additions & 2 deletions src/lib-lda/duplicate.c
Expand Up @@ -93,7 +93,7 @@ duplicate_read_records(struct duplicate_file *file, struct istream *input,
unsigned int change_count;

change_count = 0;
while (i_stream_read_data(input, &data, &size, record_size) > 0) {
while (i_stream_read_bytes(input, &data, &size, record_size) > 0) {
if (record_size == sizeof(hdr))
memcpy(&hdr, data, sizeof(hdr));
else {
Expand Down Expand Up @@ -170,7 +170,7 @@ static int duplicate_read(struct duplicate_file *file)

/* <timestamp> <id_size> <user_size> <id> <user> */
input = i_stream_create_fd(fd, DUPLICATE_BUFSIZE, FALSE);
if (i_stream_read_data(input, &data, &size, sizeof(hdr)) > 0) {
if (i_stream_read_bytes(input, &data, &size, sizeof(hdr)) > 0) {
memcpy(&hdr, data, sizeof(hdr));
if (hdr.version == 0 || hdr.version > DUPLICATE_VERSION + 10) {
/* FIXME: backwards compatibility with v1.0 */
Expand Down
4 changes: 2 additions & 2 deletions src/lib-storage/index/dbox-multi/mdbox-purge.c
Expand Up @@ -69,8 +69,8 @@ mdbox_file_read_metadata_hdr(struct dbox_file *file,
size_t size;
int ret;

ret = i_stream_read_data(file->input, &data, &size,
sizeof(*meta_hdr_r));
ret = i_stream_read_bytes(file->input, &data, &size,
sizeof(*meta_hdr_r));
if (ret <= 0) {
i_assert(ret == -1);
if (file->input->stream_errno == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/fts/fts-expunge-log.c
Expand Up @@ -447,16 +447,16 @@ fts_expunge_log_read_next(struct fts_expunge_log_read_ctx *ctx)
return NULL;

/* initial read to try to get the record */
(void)i_stream_read_data(ctx->input, &data, &size, IO_BLOCK_SIZE);
(void)i_stream_read_bytes(ctx->input, &data, &size, IO_BLOCK_SIZE);
if (size == 0 && ctx->input->stream_errno == 0) {
/* expected EOF - mark the file as read by unlinking it */
if (ctx->unlink)
i_unlink_if_exists(ctx->log->path);

/* try reading again, in case something new was written */
i_stream_sync(ctx->input);
(void)i_stream_read_data(ctx->input, &data, &size,
IO_BLOCK_SIZE);
(void)i_stream_read_bytes(ctx->input, &data, &size,
IO_BLOCK_SIZE);
}
if (size < sizeof(*rec)) {
if (size == 0 && ctx->input->stream_errno == 0) {
Expand Down

0 comments on commit d868a04

Please sign in to comment.