Skip to content

Commit bdfbc95

Browse files
author
Rafael Vanoni
committed
revert s/assert/exit changes
1 parent df70249 commit bdfbc95

6 files changed

Lines changed: 23 additions & 75 deletions

File tree

mtbl/compression.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,8 @@ _mtbl_decompress_zlib(
482482

483483
do {
484484
zret = inflate(&zs, Z_FINISH);
485-
if (zret != Z_STREAM_END && zret != Z_BUF_ERROR) {
486-
goto fail;
487-
}
488-
485+
assert(zret == Z_STREAM_END || zret == Z_BUF_ERROR);
489486
if (zret != Z_STREAM_END) {
490-
if (*output_size > SIZE_MAX / 2) {
491-
goto fail;
492-
}
493487
*output = my_realloc(*output, *output_size * 2);
494488
zs.next_out = *output + *output_size;
495489
zs.avail_out = *output_size;
@@ -499,11 +493,6 @@ _mtbl_decompress_zlib(
499493

500494
*output_size = zs.total_out;
501495
inflateEnd(&zs);
496+
502497
return (mtbl_res_success);
503-
fail:
504-
free(*output);
505-
*output = NULL;
506-
*output_size = 0;
507-
inflateEnd(&zs);
508-
return (mtbl_res_failure);
509498
}

mtbl/reader.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ reader_iter_seek(void *v,
461461
const uint8_t *key, size_t len_key)
462462
{
463463
struct reader_iter *it = (struct reader_iter *) v;
464-
464+
465465
const uint8_t *ikey, *ival;
466466
size_t len_ikey, len_ival;
467467
uint64_t new_offset;
@@ -481,7 +481,7 @@ reader_iter_seek(void *v,
481481
mtbl_varint_decode64(ival, &new_offset);
482482

483483
/* We can skip decoding a new block if our new key is within the
484-
* currently-decoded block. */
484+
* currently-decoded block. */
485485
if (it->b == NULL || it->block_offset != new_offset) {
486486
block_destroy(&it->b);
487487
block_iter_destroy(&it->bi);
@@ -523,8 +523,7 @@ reader_iter_next(void *v,
523523
return (mtbl_res_failure);
524524

525525
it->b = get_block_at_index(it->r, it->index_iter);
526-
if (it->b == NULL)
527-
return (mtbl_res_failure);
526+
assert(it->b != NULL);
528527

529528
it->bi = block_iter_init(it->b);
530529
block_iter_seek_to_first(it->bi);

mtbl/sorter.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,7 @@ mtbl_sorter_init(const struct mtbl_sorter_options *opt)
140140
if (s->opt.pool != NULL) {
141141
s->pool = s->opt.pool->pool;
142142
s->rhandler = result_handler_init(_collect_readers_cb, s);
143-
if (s->rhandler == NULL) {
144-
entry_vec_destroy(&s->vec);
145-
reader_vec_destroy(&s->readers);
146-
return (NULL);
147-
}
143+
assert(s->rhandler != NULL);
148144
}
149145

150146
return (s);
@@ -198,31 +194,16 @@ _mtbl_sorter_write_chunk(struct entry_batch *b)
198194
ubuf_append(tmp_fname, (const uint8_t *) "\x00", 1);
199195

200196
int fd = mkstemp((char *) ubuf_data(tmp_fname));
201-
if (fd < 0) {
202-
ubuf_destroy(&tmp_fname);
203-
return (NULL);
204-
}
205-
197+
assert(fd >= 0);
206198
int unlink_ret = unlink((char *) ubuf_data(tmp_fname));
207-
if (unlink_ret == -1) {
208-
ubuf_destroy(&tmp_fname);
209-
close(fd);
210-
return (NULL);
211-
}
212-
199+
assert(unlink_ret == 0);
213200
ubuf_destroy(&tmp_fname);
214201

215202
struct mtbl_writer_options *wopt = mtbl_writer_options_init();
216203
mtbl_writer_options_set_compression(wopt, MTBL_COMPRESSION_SNAPPY);
217204

218205
struct mtbl_writer *w = mtbl_writer_init_fd(fd, wopt);
219-
if (w == NULL) {
220-
mtbl_writer_options_destroy(&wopt);
221-
close(fd);
222-
entry_vec_destroy(&b->entries);
223-
free(b);
224-
return (NULL);
225-
}
206+
assert(w != NULL);
226207

227208
mtbl_writer_options_destroy(&wopt);
228209

mtbl/threadpool.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616

1717
#include <stdlib.h>
18-
#include <stdio.h>
1918
#include <pthread.h>
2019
#include <assert.h>
2120
#include <stdbool.h>
22-
#include <string.h>
2321
#include <mtbl.h>
2422

2523
#include "threadpool.h"
@@ -195,16 +193,7 @@ threadpool_next(struct threadpool *pool)
195193
pthread_cond_init(&thr->c, NULL);
196194

197195
ret = pthread_create(&thr->t, NULL, thread_worker, thr);
198-
if (ret != 0) {
199-
fprintf(stderr, "%s: pthread_create() failed: %s\n", __func__, strerror(ret));
200-
pthread_cond_destroy(&thr->c);
201-
pthread_mutex_destroy(&thr->m);
202-
free(thr);
203-
thr = NULL;
204-
pthread_mutex_lock(&pool->m);
205-
pool->count--;
206-
pthread_mutex_unlock(&pool->m);
207-
}
196+
assert(ret == 0);
208197
}
209198

210199
return thr;
@@ -400,12 +389,7 @@ result_handler_init(result_cb cb, void *cbdata)
400389
rh->cbdata = cbdata;
401390

402391
ret = pthread_create(&rh->thread, NULL, result_worker, rh);
403-
if (ret != 0) {
404-
fprintf(stderr, "%s: pthread_create() failed: %s\n", __func__, strerror(ret));
405-
resultq_destroy(&rh->rq);
406-
free(rh);
407-
return (NULL);
408-
}
392+
assert(ret == 0);
409393

410394
return rh;
411395
}
@@ -414,7 +398,9 @@ void
414398
result_handler_destroy(struct result_handler **prh)
415399
{
416400
struct result_handler *rh = *prh;
417-
if (rh == NULL) return;
401+
if (rh == NULL)
402+
return;
403+
418404
resultq_finish(rh->rq);
419405
pthread_join(rh->thread, NULL);
420406
free(rh);

mtbl/writer.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ mtbl_writer_init_fd(int orig_fd, const struct mtbl_writer_options *opt)
146146
int fd;
147147

148148
fd = dup(orig_fd);
149-
if (fd < 0) {
150-
return (NULL);
151-
}
152-
149+
assert(fd >= 0);
153150
w = my_calloc(1, sizeof(*w));
154151
if (opt == NULL) {
155152
w->opt.compression_type = DEFAULT_COMPRESSION_TYPE;
@@ -166,14 +163,9 @@ mtbl_writer_init_fd(int orig_fd, const struct mtbl_writer_options *opt)
166163
* to reserve some initial bytes in the file.
167164
*/
168165
off_t offset = lseek(fd, 0, SEEK_CUR);
169-
if (offset == (off_t)-1) {
170-
close(fd);
171-
free(w);
172-
return (NULL);
173-
}
174-
w->last_offset = (uint64_t)offset;
166+
assert(offset != (off_t)-1);
175167

176-
w->pending_offset = w->last_offset;
168+
w->pending_offset = (uint64_t)offset;
177169
w->last_key = ubuf_init(256);
178170
w->m.file_version = MTBL_FORMAT_V2;
179171
w->m.compression_algorithm = w->opt.compression_type;
@@ -185,11 +177,7 @@ mtbl_writer_init_fd(int orig_fd, const struct mtbl_writer_options *opt)
185177
if (w->opt.pool != NULL) {
186178
w->pool = w->opt.pool->pool;
187179
w->rhandler = result_handler_init(_write_data_block_wrapper, w);
188-
if (w->rhandler == NULL) {
189-
close(fd);
190-
free(w);
191-
return (NULL);
192-
}
180+
assert(w->rhandler != NULL);
193181
}
194182

195183
return (w);

src/mtbl_merge.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ merge(void)
199199
* mtbl_iter_next() returns the same value for end-of-data and error, so we check that the count equals the
200200
* sum of all input entries minus count_merged. Any shortfall means iteration stopped early.
201201
*/
202+
if (count_merged > total_input_entries) {
203+
fprintf(stderr, "%s: error: count_merged (%" PRIu64 ") exceeds total_input_entries (%" PRIu64 ")\n",
204+
program_name, count_merged, total_input_entries);
205+
exit(EXIT_FAILURE);
206+
}
202207
uint64_t expected = total_input_entries - count_merged;
203208
if (count != expected) {
204209
fprintf(stderr, "%s: error: wrote %" PRIu64 " of %" PRIu64 " expected entries; input may be truncated or corrupt\n",

0 commit comments

Comments
 (0)