free(dst);
return False;
}
- zck_index_add_to_chunk(zck, dst, dst_size, zck->comp.dict_size);
+ if(!zck_index_add_to_chunk(zck, dst, dst_size,
+ zck->comp.dict_size)) {
+ free(dst);
+ return False;
+ }
free(dst);
dst = NULL;
dst_size = 0;
free(dst);
return False;
}
- zck_index_add_to_chunk(zck, dst, dst_size, 0);
- zck_index_finish_chunk(zck);
+ if(!zck_index_add_to_chunk(zck, dst, dst_size, 0) ||
+ !zck_index_finish_chunk(zck)) {
+ free(dst);
+ return False;
+ }
free(dst);
} else {
- zck_index_finish_chunk(zck);
+ if(!zck_index_finish_chunk(zck))
+ return False;
}
}
free(zck->comp.dict);
return -1;
zck->comp.data_loc = 0;
zck->comp.data_idx = zck->comp.data_idx->next;
- zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type));
+ if(!zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
+ return -1;
return rb;
}
/* End decompression chunk if we're on a chunk boundary */
if(zck->comp.data_idx == NULL) {
zck->comp.data_idx = zck->index.first;
- zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type));
+ if(!zck_hash_init(&(zck->check_chunk_hash), &(zck->chunk_hash_type)))
+ goto zck_hash_error;
zck->comp.data_loc = 0;
}
if(zck->comp.data_loc == zck->comp.data_idx->comp_length) {
zck_log(ZCK_LOG_DEBUG, "EOF\n");
finished_rd = True;
}
- zck_hash_update(&(zck->check_full_hash), src, rb);
- zck_hash_update(&(zck->check_chunk_hash), src, rb);
- if(!zck_comp_add_to_data(&(zck->comp), src, rb))
+ if(!zck_hash_update(&(zck->check_full_hash), src, rb) ||
+ !zck_hash_update(&(zck->check_chunk_hash), src, rb) ||
+ !zck_comp_add_to_data(&(zck->comp), src, rb))
goto zck_read_error;
}
free(src);
#include <zck.h>
#include "zck_private.h"
-int zck_compint_from_size(char *compint, size_t val, size_t *length) {
+void zck_compint_from_size(char *compint, size_t val, size_t *length) {
for(unsigned char *i = (unsigned char *)compint; ; i++) {
i[0] = val % 128;
val = (val - i[0]) / 128;
break;
}
}
- return True;
+ return;
}
int zck_compint_to_size(size_t *val, const char *compint, size_t *length) {
return False;
}
- return zck_compint_from_size(compint, (size_t)val, length);
+ zck_compint_from_size(compint, (size_t)val, length);
+ return True;
}
int zck_compint_to_int(int *val, const char *compint, size_t *length) {
idx.start = *buffer_len;
idx.comp_length = start+bytes-*buffer_len;
zck_range_close(&(dl->info));
- zck_range_add(&(dl->info), &idx, NULL);
+ if(!zck_range_add(&(dl->info), &idx, NULL))
+ return False;
if(!zck_dl_range_chk_chunk(dl, url, 0))
return False;
zck_range_close(&(dl->info));
rb = to_read;
if(!read_data(dst_fd, buf, rb))
return -1;
- zck_hash_update(&(zck->check_full_hash), buf, rb);
+ if(!zck_hash_update(&(zck->check_full_hash), buf, rb))
+ return -1;
to_read -= rb;
}
idx = idx->next;
size_t length = 0;
memcpy(header+length, "\0ZCK1", 5);
length += 5;
- if(!zck_compint_from_size(header+length, zck->hash_type.type, &length)) {
- free(header);
- return False;
- }
+ zck_compint_from_size(header+length, zck->hash_type.type, &length);
/* If we have the digest, write it in, otherwise write zeros */
if(zck->index_digest)
free(header);
return False;
}
- if(!zck_compint_from_size(header+length, zck->index_size, &length)) {
- free(header);
- return False;
- }
+ zck_compint_from_size(header+length, zck->index_size, &length);
header = realloc(header, length);
if(header == NULL) {
zck_log(ZCK_LOG_ERROR, "Unable to reallocate %lu bytes\n", length);
int write_comp_size(int fd, size_t val) {
char data[sizeof(size_t)*2] = {0};
size_t length = 0;
- if(!zck_compint_from_size(data, val, &length))
- return False;
+ zck_compint_from_size(data, val, &length);
return write_data(fd, data, length);
}
if(zck->mode == ZCK_MODE_WRITE) {
if(zck_end_chunk(zck) < 0)
return False;
- zck_index_finalize(zck);
+ if(!zck_index_finalize(zck))
+ return False;
zck_log(ZCK_LOG_DEBUG, "Writing header\n");
if(!zck_write_header(zck))
return False;
if(!chunks_from_temp(zck))
return False;
zck_log(ZCK_LOG_DEBUG, "Finished writing file, cleaning up\n");
- zck_comp_close(zck);
+ if(!zck_comp_close(zck))
+ return False;
if(zck->temp_fd) {
close(zck->temp_fd);
zck->temp_fd = 0;
if(zck == NULL)
return;
zck_index_free(zck);
- zck_comp_close(zck);
+ if(!zck_comp_close(zck))
+ zck_log(ZCK_LOG_WARNING, "Unable to close compression\n");
zck_hash_close(&(zck->full_hash));
zck_hash_close(&(zck->check_full_hash));
zck_hash_close(&(zck->check_chunk_hash));
goto error;
}
}
+ if(!zck_close(zck))
+ goto error;
good_exit = True;
error:
free(data);
if(!good_exit)
unlink(out_name);
free(out_name);
- zck_close(zck);
close(src_fd);
close(dst_fd);
zck_free(&zck);
exit(1);
}
dict = malloc(dict_size);
- read(dict_fd, dict, dict_size);
+ if(read(dict_fd, dict, dict_size) < dict_size) {
+ free(dict);
+ perror("Error reading dict:");
+ exit(1);
+ }
close(dict_fd);
}
printf("Unable to open %s\n", argv[1]);
exit(1);
}
- zck_close(zck_src);
+ if(!zck_close(zck_src))
+ exit(1);
int tgt_fd = open(argv[2], O_RDONLY);
if(tgt_fd < 0) {
printf("Unable to open %s\n", argv[2]);
exit(1);
}
- zck_close(zck_tgt);
+ if(!zck_close(zck_tgt))
+ exit(1);
if(zck_get_chunk_hash_type(zck_tgt) != zck_get_chunk_hash_type(zck_src)) {
printf("ERROR: Chunk hash types don't match:\n");
perror("Unable to read header\n");
exit(1);
}
- zck_close(zck);
+ if(!zck_close(zck))
+ exit(1);
close(src_fd);
printf("Overall checksum type: %s\n", zck_hash_name_from_type(zck_get_full_hash_type(zck)));