Skip to content

Commit

Permalink
[style] Fixed a bunch of compilerwarnings
Browse files Browse the repository at this point in the history
Changed a number of strcpy strncpy
  • Loading branch information
ANGSD committed Feb 8, 2022
1 parent 139cc9a commit fbf9e13
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion abcFreq.cpp
Expand Up @@ -82,7 +82,7 @@ void abcFreq::printArg(FILE *argFile){
fprintf(argFile,"\t-minMaf \t%f\t(Remove sites with MAF below)\n",minMaf);
fprintf(argFile,"\t-SNP_pval\t%f\t(Remove sites with a pvalue larger)\n",SNP_pval);
fprintf(argFile,"\t-rmTriallelic\t%f\t(Remove sites with a pvalue lower)\n",rmTriallelic);
fprintf(argFile,"\t-forceMaf\t%f\t(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))\n",forceMaf);
fprintf(argFile,"\t-forceMaf\t%d\t(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))\n",forceMaf);
fprintf(argFile,"\t-skipMissing\t%d\t(Set post to 0.33 if missing (do not use freq as prior))\n",skipMissing);
fprintf(argFile,"Extras:\n");
fprintf(argFile,"\t-ref\t%s\t(Filename for fasta reference)\n",refName);
Expand Down
4 changes: 2 additions & 2 deletions abcScounts.cpp
Expand Up @@ -33,8 +33,8 @@ aMap readvcf(const char *fname){
if(4!=sscanf(buf,"%s\t%d\t%c\t%c\n",chr,&pos,&al1,&al2)){
fprintf(stderr,"\t-> problem parsing line: %d which looks like: %s\n",at,buf);
}
char tmpnam[1024];
sprintf(tmpnam,"%s %d",chr,pos);
char tmpnam[2048];
snprintf(tmpnam,2048,"%s %d",chr,pos);
aMap::iterator it=am.find(tmpnam);
if(it!=am.end()){
fprintf(stderr,"\t-> Problem with duplicate positions: %s \n",tmpnam);
Expand Down
3 changes: 2 additions & 1 deletion abcTemplate.cpp
Expand Up @@ -478,7 +478,8 @@ void abcTemplate::run(funkyPars *pars){

// Reference base:
int refB = -1;
if (pars->ref == 0) fprintf(outfile," Warning: Ref not defined! %s \n", pars->ref);
if (pars->ref == NULL)
fprintf(outfile,"\t-> Warning: Ref not defined! \n");
else refB = refToInt[pars->ref[s]];


Expand Down
2 changes: 1 addition & 1 deletion abcWriteBcf.cpp
Expand Up @@ -144,7 +144,7 @@ void abcWriteBcf::print(funkyPars *pars){
rec->rid = bcf_hdr_name2id(hdr,header->target_name[pars->refId]);
rec->pos = pars->posi[s];//<- maybe one index?
// bcf_update_id(hdr, rec, "rs6054257");
if(domcall!=NULL){
if(domcall>0&&mcall!=NULL){
//
char alleles[16];
int goa =0;
Expand Down
8 changes: 4 additions & 4 deletions aio.cpp
Expand Up @@ -19,7 +19,7 @@ FILE *aio::openFile(const char* a,const char* b){
fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b);
char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
// fprintf(stderr,"\t-> Dumping file: %s\n",c);
dumpedFiles.push_back(strdup(c));
FILE *fp = NULL;
Expand All @@ -36,7 +36,7 @@ BGZF *aio::openFileBG(const char* a,const char* b){

char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
dumpedFiles.push_back(strdup(c));
BGZF *fp = bgzf_open(c,"w6h");
delete [] c;
Expand All @@ -47,7 +47,7 @@ htsFile *aio::openFileHts(const char* a,const char* b){

char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
dumpedFiles.push_back(strdup(c));
htsFile *fp = hts_open(c,"w");
delete [] c;
Expand All @@ -58,7 +58,7 @@ htsFile *aio::openFileHtsBcf(const char* a,const char* b){

char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
dumpedFiles.push_back(strdup(c));
htsFile *fp = hts_open(c,"wb");
delete [] c;
Expand Down
2 changes: 1 addition & 1 deletion bgenReader.cpp
Expand Up @@ -137,7 +137,7 @@ bgenLine *bgenReader::parseline(FILE *fp,header *hd){
unsigned short Lchr_l;
assert(fread(&Lchr_l,sizeof(unsigned short),1,fp)==1);
bgen->Lchr =(char*) calloc(Lchr_l+1,sizeof(char));
fread(bgen->Lchr,sizeof(char),Lchr_l,fp);
assert(fread(bgen->Lchr,sizeof(char),Lchr_l,fp)==Lchr_l);

assert(fread(&bgen->vpos,sizeof(unsigned),1,fp)==1);
assert(fread(&bgen->nal,sizeof(unsigned short),1,fp)==1);
Expand Down
2 changes: 1 addition & 1 deletion makeReadPool.cpp
Expand Up @@ -260,7 +260,7 @@ void read_reads_noStop(htsFile *fp,int nReads,int &isEof,readPool &ret,int refTo
rdObjRegionDone =1;
break;
}else if(ret.first[ret.l+i-1]>b->core.pos){
fprintf(stderr,"[%s] unsorted file detected will exit new(-1)=%d new=%lld,ret.l=%d i=%d\n",__FUNCTION__,ret.first[ret.l+i-1],b->core.pos,ret.l,i);
fprintf(stderr,"[%s] unsorted file detected will exit new(-1)=%d new=%ld,ret.l=%d i=%d\n",__FUNCTION__,ret.first[ret.l+i-1],b->core.pos,ret.l,i);
exit(0);
}

Expand Down
2 changes: 1 addition & 1 deletion misc/fstreader.cpp
Expand Up @@ -110,7 +110,7 @@ perfst * perfst_init(char *fname){
#endif
fclose(fp);
char *tmp =(char*)calloc(strlen(fname)+100,1);//that should do it
tmp=strncpy(tmp,fname,strlen(fname)-3);
memcpy(tmp,fname,strlen(fname)-3);
// fprintf(stderr,"tmp:%s\n",tmp);

char *tmp2 = (char*)calloc(strlen(fname)+100,1);//that should do it
Expand Down
4 changes: 2 additions & 2 deletions misc/header.cpp
Expand Up @@ -28,7 +28,7 @@ BGZF *openFileBG(const char* a,const char* b){

char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
BGZF *fp = bgzf_open(c,"wb");
delete [] c;
return fp;
Expand All @@ -38,7 +38,7 @@ FILE *openFile(const char* a,const char* b){
fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b);
char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
FILE *fp = fopen(c,"w");
delete [] c;
return fp;
Expand Down
2 changes: 1 addition & 1 deletion misc/ibs.cpp
Expand Up @@ -78,7 +78,7 @@ std::vector<char *> dumpedFiles;
FILE *openFile(const char* a,const char* b){
char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
fprintf(stderr,"\t-> Dumping file: %s\n",c);

dumpedFiles.push_back(strdup(c));
Expand Down
6 changes: 3 additions & 3 deletions misc/msHOT2glf.c
Expand Up @@ -53,7 +53,7 @@ FILE *openFile(const char* a,const char* b){
// char *c = new char[strlen(a)+strlen(b)+1];
char *c = malloc(strlen(a)+strlen(b)+1);
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
// fprintf(stderr,"\t-> Dumping file: %s\n",c);
FILE *fp = getFILE(c,"w");
free(c);
Expand Down Expand Up @@ -83,7 +83,7 @@ BGZF *openFileGz(const char* a,const char* b,const char *mode){
// char *c = new char[strlen(a)+strlen(b)+1];
char *c = malloc(strlen(a)+strlen(b)+1);
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
// fprintf(stderr,"\t-> Dumping file: %s\n",c);
BGZF *fp = getGz(c,mode);
//delete [] c;
Expand Down Expand Up @@ -494,7 +494,7 @@ int main(int argc,char **argv){
char *pch = strstr(line,"msHOT-lite");
while(1){
char *tmppch=strstr(pch+1,"msHOT-lite");
if(tmppch=='\0')
if(tmppch[0]=='\0')
break;
pch=tmppch;
}
Expand Down
4 changes: 2 additions & 2 deletions misc/msToGlf.c
Expand Up @@ -603,7 +603,7 @@ FILE *openFile(const char* a,const char* b){
// char *c = new char[strlen(a)+strlen(b)+1];
char *c = malloc(strlen(a)+strlen(b)+1);
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
// fprintf(stderr,"\t-> Dumping file: %s\n",c);
FILE *fp = getFILE(c,"w");
free(c);
Expand Down Expand Up @@ -633,7 +633,7 @@ BGZF* openFileGz(const char* a,const char* b,const char *mode){
// char *c = new char[strlen(a)+strlen(b)+1];
char *c = malloc(strlen(a)+strlen(b)+1);
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
// fprintf(stderr,"\t-> Dumping file: %s\n",c);
BGZF *fp = getGz(c,mode);
//delete [] c;
Expand Down
4 changes: 2 additions & 2 deletions misc/ngsadmix32.cpp
Expand Up @@ -420,7 +420,7 @@ FILE *openFile(const char* a,const char* b){
fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b);
char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
//fprintf(stderr,"\t-> Dumping file: %s\n",c);
if(0&&fexists(c)){//ANDERS DAEMON DRAGON HATES THIS
fprintf(stderr,"File: %s exists will exist\n",c);
Expand All @@ -438,7 +438,7 @@ gzFile openFileGz(const char* a,const char* b){
fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b);
char *c = new char[strlen(a)+strlen(b)+1];
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
// fprintf(stderr,"\t-> Dumping file: %s\n",c);
if(0&&fexists(c)){//ANDERS DAEMON DRAGON HATES THIS
fprintf(stderr,"File: %s exists will exist\n",c);
Expand Down
2 changes: 1 addition & 1 deletion misc/psmcreader.cpp
Expand Up @@ -119,7 +119,7 @@ perpsmc * perpsmc_init(char *fname){
}
fclose(fp);
char *tmp =(char*)calloc(strlen(fname)+100,1);//that should do it
tmp=strncpy(tmp,fname,strlen(fname)-3);
memcpy(tmp,fname,strlen(fname)-3);
// fprintf(stderr,"tmp:%s\n",tmp);

char *tmp2 = (char*)calloc(strlen(fname)+100,1);//that should do it
Expand Down
2 changes: 1 addition & 1 deletion misc/realSFS.cpp
Expand Up @@ -254,7 +254,7 @@ int printMulti(args *arg){
for(int i=0;i<saf.size();i++){
size_t newlen = strlen(saf[i]->fname)+100;
char *tmp =(char*) calloc(newlen,sizeof(char));
tmp = strncpy(tmp,saf[i]->fname,strlen(saf[i]->fname)-4);
memcpy(tmp,saf[i]->fname,strlen(saf[i]->fname)-4);
fprintf(stderr,"\t-> Generating outputfile: %s\n",tmp);
oldfp[i] = fopen(tmp,"wb");
free(tmp);
Expand Down
4 changes: 2 additions & 2 deletions misc/safreader.cpp
Expand Up @@ -132,8 +132,8 @@ persaf * persaf_init(char *fname,int verbose){
}
}
fclose(fp);
char *tmp =(char*)calloc(strlen(fname)+100,1);//that should do it
tmp=strncpy(tmp,fname,strlen(fname)-3);
char *tmp =(char*)calloc(strlen(fname)+100,sizeof(char));//that should do it
memcpy(tmp,fname,strlen(fname)-3);
// fprintf(stderr,"tmp:%s\n",tmp);

char *tmp2 = (char*)calloc(strlen(fname)+100,1);//that should do it
Expand Down
2 changes: 1 addition & 1 deletion misc/smartCount.c
Expand Up @@ -478,7 +478,7 @@ int treemixer(int argc,char **argv){
}
++argv;
}
fprintf(stderr,"reg:%s flis:%s\n",reg,flis );
// fprintf(stderr,"reg:%s flis:%s\n",reg,flis );
if(!flis){
fprintf(stderr,"Must supply -bin/idx or bam\n");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion misc/supersim.cpp
Expand Up @@ -312,7 +312,7 @@ double simfreqBN(double F, double p_anc) {
char *append(const char* a,const char *b){
char *c =(char *) malloc((strlen(a)+strlen(b)+1)*sizeof(char));
strcpy(c,a);
strncat(c,b,strlen(b));
strcat(c,b);
return c;
}

Expand Down

0 comments on commit fbf9e13

Please sign in to comment.