[med-svn] samtools 02/26: Fix type mismatches between types in sizeof() in malloc/calloc/realloc calls. This generates a warning in the clang analyzer, designed to catch incorrectly sized memory allocations.
Charles Plessy
plessy at moszumanska.debian.org
Tue Dec 10 10:06:24 UTC 2013
This is an automated email from the git hooks/post-receive script.
plessy pushed a commit to branch debian/unstable
in repository samtools.
commit 4ce929664b2fbf912c7d47e4584e6b3924071cad
Author: Lee Baker <lee at leecbaker.com>
Date: Sun Mar 10 17:29:52 2013 -0500
Fix type mismatches between types in sizeof() in malloc/calloc/realloc calls. This generates a warning in the clang analyzer, designed to catch incorrectly sized memory allocations.
The allocation at bam_plcmd.c:208 is twice as big as it needs to be, and has been fixed.
---
bam2bcf_indel.c | 2 +-
bam2depth.c | 4 ++--
bam_import.c | 2 +-
bam_index.c | 4 ++--
bam_lpileup.c | 2 +-
bam_pileup.c | 4 ++--
bam_plcmd.c | 8 ++++----
bam_sort.c | 4 ++--
bamshuf.c | 4 ++--
bcftools/bcf.c | 2 +-
bcftools/call1.c | 2 +-
bcftools/prob1.c | 2 +-
bedcov.c | 6 +++---
faidx.c | 2 +-
kprobaln.c | 4 ++--
phase.c | 8 ++++----
razf.c | 4 ++--
sam.c | 2 +-
sam_header.c | 2 +-
sample.c | 2 +-
20 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/bam2bcf_indel.c b/bam2bcf_indel.c
index 9aea5f9..8c657e4 100644
--- a/bam2bcf_indel.c
+++ b/bam2bcf_indel.c
@@ -220,7 +220,7 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla
int L = right - left + 1, max_i, max2_i;
uint32_t *cns, max, max2;
char *ref0, *r;
- ref_sample = calloc(n, sizeof(void*));
+ ref_sample = calloc(n, sizeof(char*));
cns = calloc(L, 4);
ref0 = calloc(L, 1);
for (i = 0; i < right - left; ++i)
diff --git a/bam2depth.c b/bam2depth.c
index 02311ef..6fd023a 100644
--- a/bam2depth.c
+++ b/bam2depth.c
@@ -84,7 +84,7 @@ int main_depth(int argc, char *argv[])
}
else
n = argc - optind; // the number of BAMs on the command line
- data = calloc(n, sizeof(void*)); // data[i] for the i-th input
+ data = calloc(n, sizeof(aux_t*)); // data[i] for the i-th input
beg = 0; end = 1<<30; tid = -1; // set the default region
for (i = 0; i < n; ++i) {
bam_header_t *htmp;
@@ -107,7 +107,7 @@ int main_depth(int argc, char *argv[])
// the core multi-pileup loop
mplp = bam_mplp_init(n, read_bam, (void**)data); // initialization
n_plp = calloc(n, sizeof(int)); // n_plp[i] is the number of covering reads from the i-th BAM
- plp = calloc(n, sizeof(void*)); // plp[i] points to the array of covering reads (internal in mplp)
+ plp = calloc(n, sizeof(bam_pileup1_t*)); // plp[i] points to the array of covering reads (internal in mplp)
while (bam_mplp_auto(mplp, &tid, &pos, n_plp, plp) > 0) { // come to the next covered position
if (pos < beg || pos >= end) continue; // out of range; skip
if (bed && bed_overlap(bed, h->target_name[tid], pos, pos + 1) == 0) continue; // not in BED; skip
diff --git a/bam_import.c b/bam_import.c
index da2bf94..38c8238 100644
--- a/bam_import.c
+++ b/bam_import.c
@@ -201,7 +201,7 @@ int sam_header_parse(bam_header_t *h)
if (h->dict == 0) h->dict = sam_header_parse2(h->text);
tmp = sam_header2list(h->dict, "SQ", "SN", &h->n_targets);
if (h->n_targets == 0) return 0;
- h->target_name = calloc(h->n_targets, sizeof(void*));
+ h->target_name = calloc(h->n_targets, sizeof(char*));
for (i = 0; i < h->n_targets; ++i)
h->target_name[i] = strdup(tmp[i]);
free(tmp);
diff --git a/bam_index.c b/bam_index.c
index f916e04..85769f9 100644
--- a/bam_index.c
+++ b/bam_index.c
@@ -171,7 +171,7 @@ bam_index_t *bam_index_core(bamFile fp)
idx->n = h->n_targets;
bam_header_destroy(h);
- idx->index = (khash_t(i)**)calloc(idx->n, sizeof(void*));
+ idx->index = (khash_t(i)**)calloc(idx->n, sizeof(khash_t(i)*));
for (i = 0; i < idx->n; ++i) idx->index[i] = kh_init(i);
idx->index2 = (bam_lidx_t*)calloc(idx->n, sizeof(bam_lidx_t));
@@ -341,7 +341,7 @@ static bam_index_t *bam_index_load_core(FILE *fp)
idx = (bam_index_t*)calloc(1, sizeof(bam_index_t));
fread(&idx->n, 4, 1, fp);
if (bam_is_be) bam_swap_endian_4p(&idx->n);
- idx->index = (khash_t(i)**)calloc(idx->n, sizeof(void*));
+ idx->index = (khash_t(i)**)calloc(idx->n, sizeof(khash_t(i)*));
idx->index2 = (bam_lidx_t*)calloc(idx->n, sizeof(bam_lidx_t));
for (i = 0; i < idx->n; ++i) {
khash_t(i) *index;
diff --git a/bam_lpileup.c b/bam_lpileup.c
index d4dd63b..47f3df7 100644
--- a/bam_lpileup.c
+++ b/bam_lpileup.c
@@ -121,7 +121,7 @@ static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl
if (tv->n_nodes + 1 > tv->m_aux) { // enlarge
tv->m_aux = tv->n_nodes + 1;
kroundup32(tv->m_aux);
- tv->aux = (freenode_t**)realloc(tv->aux, sizeof(void*) * tv->m_aux);
+ tv->aux = (freenode_t**)realloc(tv->aux, sizeof(freenode_t*) * tv->m_aux);
}
for (p = tv->head, i = l = 0; p->next;) {
if (p->level > max_level) { // then discard this entry
diff --git a/bam_pileup.c b/bam_pileup.c
index 57434e0..ebae633 100644
--- a/bam_pileup.c
+++ b/bam_pileup.c
@@ -386,8 +386,8 @@ bam_mplp_t bam_mplp_init(int n, bam_plp_auto_f func, void **data)
iter = calloc(1, sizeof(struct __bam_mplp_t));
iter->pos = calloc(n, 8);
iter->n_plp = calloc(n, sizeof(int));
- iter->plp = calloc(n, sizeof(void*));
- iter->iter = calloc(n, sizeof(void*));
+ iter->plp = calloc(n, sizeof(bam_pileup1_t*));
+ iter->iter = calloc(n, sizeof(bam_plp_t));
iter->n = n;
iter->min = (uint64_t)-1;
for (i = 0; i < n; ++i) {
diff --git a/bam_plcmd.c b/bam_plcmd.c
index 8935c5a..ee4a151 100644
--- a/bam_plcmd.c
+++ b/bam_plcmd.c
@@ -203,9 +203,9 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
memset(&gplp, 0, sizeof(mplp_pileup_t));
memset(&buf, 0, sizeof(kstring_t));
memset(&bc, 0, sizeof(bcf_call_t));
- data = calloc(n, sizeof(void*));
- plp = calloc(n, sizeof(void*));
- n_plp = calloc(n, sizeof(int*));
+ data = calloc(n, sizeof(mplp_aux_t*));
+ plp = calloc(n, sizeof(bam_pileup1_t*));
+ n_plp = calloc(n, sizeof(int));
sm = bam_smpl_init();
// read the header and initialize data
@@ -248,7 +248,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
gplp.n = sm->n;
gplp.n_plp = calloc(sm->n, sizeof(int));
gplp.m_plp = calloc(sm->n, sizeof(int));
- gplp.plp = calloc(sm->n, sizeof(void*));
+ gplp.plp = calloc(sm->n, sizeof(bam_pileup1_t*));
fprintf(stderr, "[%s] %d samples in %d input files\n", __func__, sm->n, n);
// write the VCF header
diff --git a/bam_sort.c b/bam_sort.c
index c46bce3..4e04efe 100644
--- a/bam_sort.c
+++ b/bam_sort.c
@@ -117,7 +117,7 @@ int bam_merge_core2(int by_qname, const char *out, const char *headers, int n, c
iter = (bam_iter_t*)calloc(n, sizeof(bam_iter_t));
// prepare RG tag
if (flag & MERGE_RG) {
- RG = (char**)calloc(n, sizeof(void*));
+ RG = (char**)calloc(n, sizeof(char*));
RG_len = (int*)calloc(n, sizeof(int));
for (i = 0; i != n; ++i) {
int l = strlen(fn[i]);
@@ -469,7 +469,7 @@ void bam_sort_core_ext(int is_by_qname, const char *fn, const char *prefix, size
if (k == max_k) {
size_t old_max = max_k;
max_k = max_k? max_k<<1 : 0x10000;
- buf = realloc(buf, max_k * sizeof(void*));
+ buf = realloc(buf, max_k * sizeof(bam1_t*));
memset(buf + old_max, 0, sizeof(void*) * (max_k - old_max));
}
if (buf[k] == 0) buf[k] = (bam1_t*)calloc(1, sizeof(bam1_t));
diff --git a/bamshuf.c b/bamshuf.c
index 33a5238..36e8d0a 100644
--- a/bamshuf.c
+++ b/bamshuf.c
@@ -59,8 +59,8 @@ static void bamshuf(const char *fn, int n_files, const char *pre, int clevel, in
fp = strcmp(fn, "-")? bgzf_open(fn, "r") : bgzf_dopen(fileno(stdin), "r");
assert(fp);
h = bam_hdr_read(fp);
- fnt = (char**)calloc(n_files, sizeof(void*));
- fpt = (BGZF**)calloc(n_files, sizeof(void*));
+ fnt = (char**)calloc(n_files, sizeof(char*));
+ fpt = (BGZF**)calloc(n_files, sizeof(BGZF*));
cnt = (int64_t*)calloc(n_files, 8);
l = strlen(pre);
for (i = 0; i < n_files; ++i) {
diff --git a/bcftools/bcf.c b/bcftools/bcf.c
index 24728db..135e8b3 100644
--- a/bcftools/bcf.c
+++ b/bcftools/bcf.c
@@ -75,7 +75,7 @@ static inline char **cnt_null(int l, char *str, int *_n)
for (p = str; p != str + l; ++p)
if (*p == 0) ++n;
*_n = n;
- list = calloc(n, sizeof(void*));
+ list = calloc(n, sizeof(char*));
list[0] = str;
for (p = str, n = 1; p < str + l - 1; ++p)
if (*p == 0) list[n++] = p + 1;
diff --git a/bcftools/call1.c b/bcftools/call1.c
index 5f32c34..317b161 100644
--- a/bcftools/call1.c
+++ b/bcftools/call1.c
@@ -196,7 +196,7 @@ static char **read_samples(const char *fn, int *_n)
int l;
if (max == n) {
max = max? max<<1 : 4;
- sam = realloc(sam, sizeof(void*)*max);
+ sam = realloc(sam, sizeof(char*)*max);
}
l = s.l;
sam[n] = malloc(s.l + 2);
diff --git a/bcftools/prob1.c b/bcftools/prob1.c
index ffa608e..79b1cff 100644
--- a/bcftools/prob1.c
+++ b/bcftools/prob1.c
@@ -663,7 +663,7 @@ static double contrast2(bcf_p1aux_t *p1, double ret[3])
computation in this block can be accelerated with a similar strategy, but perhaps this
is not a serious concern for now. */
double tmp = lgamma(2*(n1+n2)+1) - (lgamma(2*n1+1) + lgamma(2*n2+1));
- p1->hg = calloc(2*n1+1, sizeof(void*));
+ p1->hg = calloc(2*n1+1, sizeof(double*));
for (k1 = 0; k1 <= 2*n1; ++k1) {
p1->hg[k1] = calloc(2*n2+1, sizeof(double));
for (k2 = 0; k2 <= 2*n2; ++k2)
diff --git a/bedcov.c b/bedcov.c
index 3e4b952..a0b506c 100644
--- a/bedcov.c
+++ b/bedcov.c
@@ -49,8 +49,8 @@ int main_bedcov(int argc, char *argv[])
}
memset(&str, 0, sizeof(kstring_t));
n = argc - optind - 1;
- aux = calloc(n, sizeof(void*));
- idx = calloc(n, sizeof(void*));
+ aux = calloc(n, sizeof(aux_t*));
+ idx = calloc(n, sizeof(bam_index_t*));
for (i = 0; i < n; ++i) {
aux[i] = calloc(1, sizeof(aux_t));
aux[i]->min_mapQ = min_mapQ;
@@ -69,7 +69,7 @@ int main_bedcov(int argc, char *argv[])
fp = gzopen(argv[optind], "rb");
ks = ks_init(fp);
n_plp = calloc(n, sizeof(int));
- plp = calloc(n, sizeof(void*));
+ plp = calloc(n, sizeof(bam_pileup1_t*));
while (ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) {
char *p, *q;
int tid, beg, end, pos;
diff --git a/faidx.c b/faidx.c
index 51c82ac..5647887 100644
--- a/faidx.c
+++ b/faidx.c
@@ -52,7 +52,7 @@ static inline void fai_insert_index(faidx_t *idx, const char *name, int len, int
faidx1_t t;
if (idx->n == idx->m) {
idx->m = idx->m? idx->m<<1 : 16;
- idx->name = (char**)realloc(idx->name, sizeof(void*) * idx->m);
+ idx->name = (char**)realloc(idx->name, sizeof(char*) * idx->m);
}
idx->name[idx->n] = strdup(name);
k = kh_put(s, idx->hash, idx->name[idx->n], &ret);
diff --git a/kprobaln.c b/kprobaln.c
index 04e526a..ec0247a 100644
--- a/kprobaln.c
+++ b/kprobaln.c
@@ -87,8 +87,8 @@ int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_quer
if (bw < abs(l_ref - l_query)) bw = abs(l_ref - l_query);
bw2 = bw * 2 + 1;
// allocate the forward and backward matrices f[][] and b[][] and the scaling array s[]
- f = calloc(l_query+1, sizeof(void*));
- if (is_backward) b = calloc(l_query+1, sizeof(void*));
+ f = calloc(l_query+1, sizeof(double*));
+ if (is_backward) b = calloc(l_query+1, sizeof(double*));
for (i = 0; i <= l_query; ++i) { // FIXME: this will lead in segfault for l_query==0
f[i] = calloc(bw2 * 3 + 6, sizeof(double)); // FIXME: this is over-allocated for very short seqs
if (is_backward) b[i] = calloc(bw2 * 3 + 6, sizeof(double));
diff --git a/phase.c b/phase.c
index ef4eff9..870e9cb 100644
--- a/phase.c
+++ b/phase.c
@@ -87,7 +87,7 @@ static int **count_all(int l, int vpos, nseq_t *hash)
int i, j, **cnt;
uint8_t *seq;
seq = calloc(l, 1);
- cnt = calloc(vpos, sizeof(void*));
+ cnt = calloc(vpos, sizeof(int*));
for (i = 0; i < vpos; ++i) cnt[i] = calloc(1<<l, sizeof(int));
for (k = 0; k < kh_end(hash); ++k) {
if (kh_exist(hash, k)) {
@@ -116,7 +116,7 @@ static int8_t *dynaprog(int l, int vpos, int **w)
uint32_t x, z = 1u<<(l-1), mask = (1u<<l) - 1;
f[0] = calloc(z, sizeof(int));
f[1] = calloc(z, sizeof(int));
- b = calloc(vpos, sizeof(void*));
+ b = calloc(vpos, sizeof(int8_t*));
prev = f[0]; curr = f[1];
// fill the backtrack matrix
for (i = 0; i < vpos; ++i) {
@@ -405,7 +405,7 @@ static int phase(phaseg_t *g, const char *chr, int vpos, uint64_t *cns, nseq_t *
i + g->vpos_shift + 1, (int)(x&0xffff), (int)(x>>16&0xffff), (int)(x>>32&0xffff), (int)(x>>48&0xffff));
}
free(path); free(pcnt); free(regmask); free(sitemask);
- seqs = calloc(n_seqs, sizeof(void*));
+ seqs = calloc(n_seqs, sizeof(frag_t*));
for (k = 0, i = 0; k < kh_end(hash); ++k)
if (kh_exist(hash, k) && kh_val(hash, k).vpos < vpos && !kh_val(hash, k).single)
seqs[i++] = &kh_val(hash, k);
@@ -455,7 +455,7 @@ static int readaln(void *data, bam1_t *b)
if (!(b->core.flag & (BAM_FUNMAP|BAM_FSECONDARY|BAM_FQCFAIL|BAM_FDUP)) && g->pre) {
if (g->n == g->m) {
g->m = g->m? g->m<<1 : 16;
- g->b = realloc(g->b, g->m * sizeof(void*));
+ g->b = realloc(g->b, g->m * sizeof(bam1_t*));
}
g->b[g->n++] = bam_dup1(b);
}
diff --git a/razf.c b/razf.c
index e7499f9..20aaacb 100644
--- a/razf.c
+++ b/razf.c
@@ -81,7 +81,7 @@ static inline int is_big_endian(){
static void add_zindex(RAZF *rz, int64_t in, int64_t out){
if(rz->index->size == rz->index->cap){
rz->index->cap = rz->index->cap * 1.5 + 2;
- rz->index->cell_offsets = realloc(rz->index->cell_offsets, sizeof(int) * rz->index->cap);
+ rz->index->cell_offsets = realloc(rz->index->cell_offsets, sizeof(uint32_t) * rz->index->cap);
rz->index->bin_offsets = realloc(rz->index->bin_offsets, sizeof(int64_t) * (rz->index->cap/RZ_BIN_SIZE + 1));
}
if(rz->index->size % RZ_BIN_SIZE == 0) rz->index->bin_offsets[rz->index->size / RZ_BIN_SIZE] = out;
@@ -132,7 +132,7 @@ static void load_zindex(RAZF *rz, int fd){
#else
read(fd, rz->index->bin_offsets, sizeof(int64_t) * v32);
#endif
- rz->index->cell_offsets = malloc(sizeof(int) * rz->index->size);
+ rz->index->cell_offsets = malloc(sizeof(uint32_t) * rz->index->size);
#ifdef _USE_KNETFILE
knet_read(fp, rz->index->cell_offsets, sizeof(int) * rz->index->size);
#else
diff --git a/sam.c b/sam.c
index fa11df6..6a2ab80 100644
--- a/sam.c
+++ b/sam.c
@@ -16,7 +16,7 @@ bam_header_t *bam_header_dup(const bam_header_t *h0)
h->text = (char*)calloc(h->l_text + 1, 1);
memcpy(h->text, h0->text, h->l_text);
h->target_len = (uint32_t*)calloc(h->n_targets, 4);
- h->target_name = (char**)calloc(h->n_targets, sizeof(void*));
+ h->target_name = (char**)calloc(h->n_targets, sizeof(char*));
for (i = 0; i < h->n_targets; ++i) {
h->target_len[i] = h0->target_len[i];
h->target_name[i] = strdup(h0->target_name[i]);
diff --git a/sam_header.c b/sam_header.c
index ddc2c38..ced0c8e 100644
--- a/sam_header.c
+++ b/sam_header.c
@@ -660,7 +660,7 @@ char **sam_header2list(const void *_dict, char type[2], char key_tag[2], int *_n
if (n == max) {
max = max? max<<1 : 4;
- ret = realloc(ret, max * sizeof(void*));
+ ret = realloc(ret, max * sizeof(char*));
}
ret[n++] = key->value;
diff --git a/sample.c b/sample.c
index 830b9d1..294b12b 100644
--- a/sample.c
+++ b/sample.c
@@ -40,7 +40,7 @@ static void add_pair(bam_sample_t *sm, khash_t(sm) *sm2id, const char *key, cons
if (k_sm == kh_end(sm2id)) { // absent
if (sm->n == sm->m) {
sm->m = sm->m? sm->m<<1 : 1;
- sm->smpl = realloc(sm->smpl, sizeof(void*) * sm->m);
+ sm->smpl = realloc(sm->smpl, sizeof(char*) * sm->m);
}
sm->smpl[sm->n] = strdup(val);
k_sm = kh_put(sm, sm2id, sm->smpl[sm->n], &ret);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/samtools.git
More information about the debian-med-commit
mailing list