Skip to content

Commit

Permalink
Fix undefined behavior leading to differences in output
Browse files Browse the repository at this point in the history
This fixes output differences seen when compiled with old/new GCC versions.
#34
  • Loading branch information
unode committed Nov 13, 2017
1 parent 004218f commit cbbb5db
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
63 changes: 38 additions & 25 deletions gene.c
Expand Up @@ -259,6 +259,8 @@ void record_gene_data(struct _gene *genes, int ng, struct _node *nod,
strcpy(sd_string[27], "AGGAGG");
strcpy(sd_spacer[27], "5-10bp");

char buffer[500] = {0};

for(i = 0; i < ng; i++) {
ndx = genes[i].start_ndx;
sndx = genes[i].stop_ndx;
Expand All @@ -282,35 +284,42 @@ void record_gene_data(struct _gene *genes, int ng, struct _node *nod,
rbs1 = tinf->rbs_wt[nod[ndx].rbs[0]]*tinf->st_wt;
rbs2 = tinf->rbs_wt[nod[ndx].rbs[1]]*tinf->st_wt;
if(tinf->uses_sd == 1) {
if(rbs1 > rbs2)
sprintf(genes[i].gene_data, "%srbs_motif=%s;rbs_spacer=%s",
genes[i].gene_data, sd_string[nod[ndx].rbs[0]],
if(rbs1 > rbs2) {
sprintf(buffer, "rbs_motif=%s;rbs_spacer=%s",
sd_string[nod[ndx].rbs[0]],
sd_spacer[nod[ndx].rbs[0]]);
else
sprintf(genes[i].gene_data, "%srbs_motif=%s;rbs_spacer=%s",
genes[i].gene_data, sd_string[nod[ndx].rbs[1]],
strcat(genes[i].gene_data, buffer);
} else {
sprintf(buffer, "rbs_motif=%s;rbs_spacer=%s",
sd_string[nod[ndx].rbs[1]],
sd_spacer[nod[ndx].rbs[1]]);
strcat(genes[i].gene_data, buffer);
}
}
else {
mer_text(qt, nod[ndx].mot.len, nod[ndx].mot.ndx);
if(tinf->no_mot > -0.5 && rbs1 > rbs2 && rbs1 > nod[ndx].mot.score *
tinf->st_wt)
sprintf(genes[i].gene_data, "%srbs_motif=%s;rbs_spacer=%s",
genes[i].gene_data, sd_string[nod[ndx].rbs[0]],
tinf->st_wt) {
sprintf(buffer, "rbs_motif=%s;rbs_spacer=%s",
sd_string[nod[ndx].rbs[0]],
sd_spacer[nod[ndx].rbs[0]]);
else if(tinf->no_mot > -0.5 && rbs2 >= rbs1 && rbs2 > nod[ndx].mot.score *
tinf->st_wt)
sprintf(genes[i].gene_data, "%srbs_motif=%s;rbs_spacer=%s",
genes[i].gene_data, sd_string[nod[ndx].rbs[1]],
strcat(genes[i].gene_data, buffer);
} else if(tinf->no_mot > -0.5 && rbs2 >= rbs1 && rbs2 > nod[ndx].mot.score *
tinf->st_wt) {
sprintf(buffer, "rbs_motif=%s;rbs_spacer=%s",
sd_string[nod[ndx].rbs[1]],
sd_spacer[nod[ndx].rbs[1]]);
else if(nod[ndx].mot.len == 0)
sprintf(genes[i].gene_data, "%srbs_motif=None;rbs_spacer=None",
genes[i].gene_data);
else sprintf(genes[i].gene_data, "%srbs_motif=%s;rbs_spacer=%dbp",
genes[i].gene_data, qt, nod[ndx].mot.spacer);
strcat(genes[i].gene_data, buffer);
} else if(nod[ndx].mot.len == 0) {
strcat(genes[i].gene_data, "rbs_motif=None;rbs_spacer=None");
} else {
sprintf(buffer, "rbs_motif=%s;rbs_spacer=%dbp",
qt, nod[ndx].mot.spacer);
strcat(genes[i].gene_data, buffer);
}
}
sprintf(genes[i].gene_data, "%s;gc_cont=%.3f", genes[i].gene_data,
nod[ndx].gc_cont);
sprintf(buffer, ";gc_cont=%.3f", nod[ndx].gc_cont);
strcat(genes[i].gene_data, buffer);

/* Record score data */
confidence = calculate_confidence(nod[ndx].cscore + nod[ndx].sscore,
Expand All @@ -319,8 +328,9 @@ void record_gene_data(struct _gene *genes, int ng, struct _node *nod,
"conf=%.2f;score=%.2f;cscore=%.2f;sscore=%.2f;rscore=%.2f;uscore=%.2f;",
confidence, nod[ndx].cscore+nod[ndx].sscore,nod[ndx].cscore,
nod[ndx].sscore, nod[ndx].rscore, nod[ndx].uscore);
sprintf(genes[i].score_data, "%stscore=%.2f;", genes[i].score_data,
nod[ndx].tscore);

sprintf(buffer, "tscore=%.2f;", nod[ndx].tscore);
strcat(genes[i].score_data, buffer);
}

}
Expand All @@ -333,21 +343,24 @@ void print_genes(FILE *fp, struct _gene *genes, int ng, struct _node *nod,
int i, ndx, sndx;
char left[50], right[50];
char seq_data[MAX_LINE*2], run_data[MAX_LINE];
char buffer[MAX_LINE] = {0};

/* Initialize sequence data */
sprintf(seq_data, "seqnum=%d;seqlen=%d;seqhdr=\"%s\"", sctr, slen, header);

/* Initialize run data string */
if(is_meta == 0) {
sprintf(run_data, "version=Prodigal.v%s;run_type=Single;", version);
sprintf(run_data, "%smodel=\"Ab initio\";", run_data);
strcat(run_data, "model=\"Ab initio\";");
}
else {
sprintf(run_data, "version=Prodigal.v%s;run_type=Metagenomic;", version);
sprintf(run_data, "%smodel=\"%s\";", run_data, mdesc);
sprintf(buffer, "model=\"%s\";", mdesc);
strcat(run_data, buffer);
}
sprintf(run_data, "%sgc_cont=%.2f;transl_table=%d;uses_sd=%d", run_data,
sprintf(buffer, "gc_cont=%.2f;transl_table=%d;uses_sd=%d",
tinf->gc*100.0, tinf->trans_table, tinf->uses_sd);
strcat(run_data, buffer);

strcpy(left, "");
strcpy(right, "");
Expand Down
9 changes: 6 additions & 3 deletions node.c
Expand Up @@ -1412,21 +1412,24 @@ void write_start_file(FILE *fh, struct _node *nod, int nn, struct _training
char sd_string[28][100], sd_spacer[28][20], qt[10];
char type_string[4][5] = { "ATG", "GTG", "TTG" , "Edge" };
char seq_data[MAX_LINE*2], run_data[MAX_LINE];
char buffer[MAX_LINE] = {0};

/* Initialize sequence data */
sprintf(seq_data, "seqnum=%d;seqlen=%d;seqhdr=\"%s\"", sctr, slen, header);

/* Initialize run data string */
if(is_meta == 0) {
sprintf(run_data, "version=Prodigal.v%s;run_type=Single;", version);
sprintf(run_data, "%smodel=\"Ab initio\";", run_data);
strcat(run_data, "model=\"Ab initio\";");
}
else {
sprintf(run_data, "version=Prodigal.v%s;run_type=Metagenomic;", version);
sprintf(run_data, "%smodel=\"%s\";", run_data, mdesc);
sprintf(buffer, "model=\"%s\";", mdesc);
strcat(run_data, buffer);
}
sprintf(run_data, "%sgc_cont=%.2f;transl_table=%d;uses_sd=%d", run_data,
sprintf(buffer, "gc_cont=%.2f;transl_table=%d;uses_sd=%d",
tinf->gc*100.0, tinf->trans_table, tinf->uses_sd);
strcat(run_data, buffer);

strcpy(sd_string[0], "None");
strcpy(sd_spacer[0], "None");
Expand Down

0 comments on commit cbbb5db

Please sign in to comment.