Skip to content

Commit b13f80a

Browse files
daviesrobjkbonfield
authored andcommitted
Move misplaced NULL pointer checks
Found using Coccinelle. No problems have been reported due to these, but it is good form to have them in the right place.
1 parent b8863d7 commit b13f80a

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

cram/cram_io.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,10 +2427,10 @@ static void ref_entry_free_seq(ref_entry *e) {
24272427
void refs_free(refs_t *r) {
24282428
RP("refs_free()\n");
24292429

2430-
if (--r->count > 0)
2430+
if (!r)
24312431
return;
24322432

2433-
if (!r)
2433+
if (--r->count > 0)
24342434
return;
24352435

24362436
if (r->pool)
@@ -3434,24 +3434,13 @@ char *cram_get_ref(cram_fd *fd, int id, hts_pos_t start, hts_pos_t end) {
34343434

34353435

34363436
/* Sanity checking: does this ID exist? */
3437-
if (id >= fd->refs->nref) {
3438-
hts_log_error("No reference found for id %d", id);
3439-
pthread_mutex_unlock(&fd->ref_lock);
3440-
return NULL;
3441-
}
3442-
3443-
if (!fd->refs || !fd->refs->ref_id[id]) {
3444-
hts_log_error("No reference found for id %d", id);
3445-
pthread_mutex_unlock(&fd->ref_lock);
3446-
return NULL;
3447-
}
3448-
3449-
if (!(r = fd->refs->ref_id[id])) {
3437+
if (!fd->refs || id < 0 || id >= fd->refs->nref || !fd->refs->ref_id[id]) {
34503438
hts_log_error("No reference found for id %d", id);
34513439
pthread_mutex_unlock(&fd->ref_lock);
34523440
return NULL;
34533441
}
34543442

3443+
r = fd->refs->ref_id[id];
34553444

34563445
/*
34573446
* It has an entry, but may not have been populated yet.

0 commit comments

Comments
 (0)