Skip to content

Commit 510fce0

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

5 files changed

Lines changed: 18 additions & 73 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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,7 @@ threadpool_next(struct threadpool *pool)
195195
pthread_cond_init(&thr->c, NULL);
196196

197197
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-
}
198+
assert(ret == 0);
208199
}
209200

210201
return thr;
@@ -400,12 +391,7 @@ result_handler_init(result_cb cb, void *cbdata)
400391
rh->cbdata = cbdata;
401392

402393
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-
}
394+
assert(ret == 0);
409395

410396
return rh;
411397
}
@@ -414,7 +400,9 @@ void
414400
result_handler_destroy(struct result_handler **prh)
415401
{
416402
struct result_handler *rh = *prh;
417-
if (rh == NULL) return;
403+
if (rh == NULL)
404+
return;
405+
418406
resultq_finish(rh->rq);
419407
pthread_join(rh->thread, NULL);
420408
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);

0 commit comments

Comments
 (0)