From: Roland Schulz Date: Mon, 7 Jul 2014 21:44:28 +0000 (-0400) Subject: Replace most strdup with gmx_strdup X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=a38140b32f9a0ab3599fab3b1cec4c72e57063e8;p=alexxy%2Fgromacs.git Replace most strdup with gmx_strdup gmx_strdup existed but code was using a mixture of it and strdup. Advantages of using gmx_strudup everywhere: - consistency - error handling for out of memory - strdup might not be available (e.g. Cygwin) Left strdup in testutils which had already error handling. And fatalerror.cpp which cannot use gmx_strdup because it could lead to an infinite loop. If all strdup are removed gnu++0x in gmxTestCXX11.cmake is not required anymore. Change-Id: I6ed3e17e34b833b01222d4b45c680db7aadada34 --- diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 394205f590..8ddff6fb8c 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -431,8 +431,7 @@ void OptionsAdapter::copyValues(bool bReadNode) snew(file->fnm->fns, file->fnm->nfiles); for (int i = 0; i < file->fnm->nfiles; ++i) { - // TODO: Check for out-of-memory. - file->fnm->fns[i] = strdup(file->values[i].c_str()); + file->fnm->fns[i] = gmx_strdup(file->values[i].c_str()); } } std::list::const_iterator arg; diff --git a/src/gromacs/essentialdynamics/edsam.c b/src/gromacs/essentialdynamics/edsam.c index 1011b04b3a..55aceb558b 100644 --- a/src/gromacs/essentialdynamics/edsam.c +++ b/src/gromacs/essentialdynamics/edsam.c @@ -1138,7 +1138,7 @@ static void get_flood_enx_names(t_edpar *edi, char** names, int *nnames) /* get { srenew(names, count); sprintf(buf, "Vfl_%d", count); - names[count-1] = strdup(buf); + names[count-1] = gmx_strdup(buf); actual = actual->next_edi; count++; } @@ -2452,7 +2452,7 @@ static void nice_legend(const char ***setname, int *nsets, char **LegendStr, cha sprintf(tmp, "%c %s", EDgroupchar, value); add_to_string_aligned(LegendStr, tmp); sprintf(tmp2, "%s (%s)", tmp, unit); - (*setname)[*nsets] = strdup(tmp2); + (*setname)[*nsets] = gmx_strdup(tmp2); (*nsets)++; } diff --git a/src/gromacs/fileio/confio.c b/src/gromacs/fileio/confio.c index 4bddce5400..32ad75f5c7 100644 --- a/src/gromacs/fileio/confio.c +++ b/src/gromacs/fileio/confio.c @@ -256,7 +256,7 @@ int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line) if (fr->title == NULL) { fgets2(line, STRLEN, fp); - fr->title = strdup(line); + fr->title = gmx_strdup(line); } bEnd = FALSE; while (!bEnd && fgets2(line, STRLEN, fp)) diff --git a/src/gromacs/fileio/enxio.c b/src/gromacs/fileio/enxio.c index 8f164e6333..f77d26ab0b 100644 --- a/src/gromacs/fileio/enxio.c +++ b/src/gromacs/fileio/enxio.c @@ -375,7 +375,7 @@ static void edr_strings(XDR *xdr, gmx_bool bRead, int file_version, } else { - nm->unit = strdup("kJ/mol"); + nm->unit = gmx_strdup("kJ/mol"); } } } diff --git a/src/gromacs/fileio/filenm.c b/src/gromacs/fileio/filenm.c index 45f1822639..dad39b9f23 100644 --- a/src/gromacs/fileio/filenm.c +++ b/src/gromacs/fileio/filenm.c @@ -561,7 +561,7 @@ int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix) *extpos = '\0'; sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1); sfree(fnm[i].fns[j]); - fnm[i].fns[j] = strdup(newname); + fnm[i].fns[j] = gmx_strdup(newname); } } } @@ -579,7 +579,7 @@ t_filenm *dup_tfn(int nf, const t_filenm tfn[]) ret[i] = tfn[i]; /* just directly copy all non-string fields */ if (tfn[i].opt) { - ret[i].opt = strdup(tfn[i].opt); + ret[i].opt = gmx_strdup(tfn[i].opt); } else { @@ -588,7 +588,7 @@ t_filenm *dup_tfn(int nf, const t_filenm tfn[]) if (tfn[i].fn) { - ret[i].fn = strdup(tfn[i].fn); + ret[i].fn = gmx_strdup(tfn[i].fn); } else { @@ -600,7 +600,7 @@ t_filenm *dup_tfn(int nf, const t_filenm tfn[]) snew(ret[i].fns, tfn[i].nfiles); for (j = 0; j < tfn[i].nfiles; j++) { - ret[i].fns[j] = strdup(tfn[i].fns[j]); + ret[i].fns[j] = gmx_strdup(tfn[i].fns[j]); } } } diff --git a/src/gromacs/fileio/gmxfio.c b/src/gromacs/fileio/gmxfio.c index 1aed4f145a..20bcb37848 100644 --- a/src/gromacs/fileio/gmxfio.c +++ b/src/gromacs/fileio/gmxfio.c @@ -487,7 +487,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode) if (fn) { fio->iFTP = fn2ftp(fn); - fio->fn = strdup(fn); + fio->fn = gmx_strdup(fn); fio->bStdio = FALSE; /* If this file type is in the list of XDR files, open it like that */ @@ -549,7 +549,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode) /* Use stdin/stdout for I/O */ fio->iFTP = efTPA; fio->fp = bRead ? stdin : stdout; - fio->fn = strdup("STDIO"); + fio->fn = gmx_strdup("STDIO"); fio->bStdio = TRUE; } fio->bRead = bRead; diff --git a/src/gromacs/fileio/matio.cpp b/src/gromacs/fileio/matio.cpp index 9a223a3dfe..94007d1216 100644 --- a/src/gromacs/fileio/matio.cpp +++ b/src/gromacs/fileio/matio.cpp @@ -143,7 +143,7 @@ int getcmap(FILE *in, const char *fn, t_mapping **map) sscanf(line, "%s%s%lf%lf%lf", code, desc, &r, &g, &b); m[i].code.c1 = code[0]; m[i].code.c2 = 0; - m[i].desc = strdup(desc); + m[i].desc = gmx_strdup(desc); m[i].rgb.r = r; m[i].rgb.g = g; m[i].rgb.b = b; @@ -423,7 +423,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) line = strchr(line, '\"'); line++; line2string(&line); - map[m].desc = strdup(line); + map[m].desc = gmx_strdup(line); m++; } } diff --git a/src/gromacs/fileio/strdb.c b/src/gromacs/fileio/strdb.c index 3ceca94be8..b8811a5fb4 100644 --- a/src/gromacs/fileio/strdb.c +++ b/src/gromacs/fileio/strdb.c @@ -143,7 +143,7 @@ int get_strings(const char *db, char ***strings) #ifdef DEBUG fprintf(stderr, "Have read: %s\n", buf); #endif - ptr[i] = strdup(buf); + ptr[i] = gmx_strdup(buf); } gmx_ffclose(in); @@ -224,7 +224,7 @@ int get_file(const char *db, char ***strings) maxi += 50; srenew(ptr, maxi); } - ptr[i] = strdup(buf); + ptr[i] = gmx_strdup(buf); i++; } nstr = i; diff --git a/src/gromacs/fileio/tpxio.c b/src/gromacs/fileio/tpxio.c index 96c948f9a6..5004a86664 100644 --- a/src/gromacs/fileio/tpxio.c +++ b/src/gromacs/fileio/tpxio.c @@ -2723,7 +2723,7 @@ static void do_symtab(t_fileio *fio, t_symtab *symtab, gmx_bool bRead) for (i = 0; (i < nr); i++) { gmx_fio_do_string(fio, buf); - symbuf->buf[i] = strdup(buf); + symbuf->buf[i] = gmx_strdup(buf); } } else diff --git a/src/gromacs/fileio/xvgr.cpp b/src/gromacs/fileio/xvgr.cpp index d8a4e729a3..dddc4afc89 100644 --- a/src/gromacs/fileio/xvgr.cpp +++ b/src/gromacs/fileio/xvgr.cpp @@ -534,17 +534,17 @@ static char *read_xvgr_string(const char *line) ptr1 = strchr(ptr0, '"'); if (ptr1 != NULL) { - str = strdup(ptr0); + str = gmx_strdup(ptr0); str[ptr1-ptr0] = '\0'; } else { - str = strdup(""); + str = gmx_strdup(""); } } else { - str = strdup(""); + str = gmx_strdup(""); } return str; diff --git a/src/gromacs/gmxana/gmx_anaeig.c b/src/gromacs/gmxana/gmx_anaeig.c index eb1d28e6b6..6cef5adfea 100644 --- a/src/gromacs/gmxana/gmx_anaeig.c +++ b/src/gromacs/gmxana/gmx_anaeig.c @@ -646,7 +646,7 @@ static void project(const char *trajfile, t_topology *top, int ePBC, matrix topb for (v = 0; v < noutvec; v++) { sprintf(str, "vec %d", eignr[outvec[v]]+1); - ylabel[v] = strdup(str); + ylabel[v] = gmx_strdup(str); } sprintf(str, "projection on eigenvectors (%s)", proj_unit); write_xvgr_graphs(projfile, noutvec, 1, str, NULL, output_env_get_xvgr_tlabel(oenv), @@ -712,8 +712,8 @@ static void project(const char *trajfile, t_topology *top, int ePBC, matrix topb init_t_atoms(&atoms, nframes, FALSE); snew(x, nframes); snew(b, nframes); - atnm = strdup("C"); - resnm = strdup("PRJ"); + atnm = gmx_strdup("C"); + resnm = gmx_strdup("PRJ"); if (nframes > 10000) { @@ -878,7 +878,7 @@ static void components(const char *outfile, int natoms, { v = outvec[g]; sprintf(str, "vec %d", eignr[v]+1); - ylabel[g] = strdup(str); + ylabel[g] = gmx_strdup(str); snew(y[g], 4); for (s = 0; s < 4; s++) { @@ -935,7 +935,7 @@ static void rmsf(const char *outfile, int natoms, real *sqrtm, gmx_fatal(FARGS, "Selected vector %d is larger than the number of eigenvalues (%d)", eignr[v]+1, neig); } sprintf(str, "vec %d", eignr[v]+1); - ylabel[g] = strdup(str); + ylabel[g] = gmx_strdup(str); snew(y[g], natoms); for (i = 0; i < natoms; i++) { diff --git a/src/gromacs/gmxana/gmx_chi.c b/src/gromacs/gmxana/gmx_chi.c index f95e495f10..031e7e7ee0 100644 --- a/src/gromacs/gmxana/gmx_chi.c +++ b/src/gromacs/gmxana/gmx_chi.c @@ -681,15 +681,15 @@ static void histogramming(FILE *log, int nbin, gmx_residuetype_t *rt, snew(leg, NJC); for (i = 0; (i < NKKKPHI); i++) { - leg[i] = strdup(kkkphi[i].name); + leg[i] = gmx_strdup(kkkphi[i].name); } for (i = 0; (i < NKKKPSI); i++) { - leg[i+NKKKPHI] = strdup(kkkpsi[i].name); + leg[i+NKKKPHI] = gmx_strdup(kkkpsi[i].name); } for (i = 0; (i < NKKKCHI); i++) { - leg[i+NKKKPHI+NKKKPSI] = strdup(kkkchi1[i].name); + leg[i+NKKKPHI+NKKKPSI] = gmx_strdup(kkkchi1[i].name); } xvgr_legend(fp, NJC, (const char**)leg, oenv); fprintf(fp, "%5s ", "#Res."); @@ -1018,15 +1018,15 @@ static void print_transitions(const char *fn, int maxchi, int nlist, char *leg[edMax]; #define NLEG asize(leg) - leg[0] = strdup("Phi"); - leg[1] = strdup("Psi"); - leg[2] = strdup("Omega"); - leg[3] = strdup("Chi1"); - leg[4] = strdup("Chi2"); - leg[5] = strdup("Chi3"); - leg[6] = strdup("Chi4"); - leg[7] = strdup("Chi5"); - leg[8] = strdup("Chi6"); + leg[0] = gmx_strdup("Phi"); + leg[1] = gmx_strdup("Psi"); + leg[2] = gmx_strdup("Omega"); + leg[3] = gmx_strdup("Chi1"); + leg[4] = gmx_strdup("Chi2"); + leg[5] = gmx_strdup("Chi3"); + leg[6] = gmx_strdup("Chi4"); + leg[7] = gmx_strdup("Chi5"); + leg[8] = gmx_strdup("Chi6"); /* Print order parameters */ fp = xvgropen(fn, "Dihedral Rotamer Transitions", "Residue", "Transitions/ns", @@ -1082,7 +1082,7 @@ static void order_params(FILE *log, for (i = 0; i < NLEG; i++) { - leg[i] = strdup(const_leg[i]); + leg[i] = gmx_strdup(const_leg[i]); } /* Print order parameters */ diff --git a/src/gromacs/gmxana/gmx_clustsize.c b/src/gromacs/gmxana/gmx_clustsize.c index 787aeb8910..ad1ee19258 100644 --- a/src/gromacs/gmxana/gmx_clustsize.c +++ b/src/gromacs/gmxana/gmx_clustsize.c @@ -147,7 +147,7 @@ static void clust_size(const char *ndx, const char *trx, const char *xpm, { index[i] = i; } - gname = strdup("mols"); + gname = gmx_strdup("mols"); } else { diff --git a/src/gromacs/gmxana/gmx_density.c b/src/gromacs/gmxana/gmx_density.c index ab0ee0b7e0..a0caf03c6d 100644 --- a/src/gromacs/gmxana/gmx_density.c +++ b/src/gromacs/gmxana/gmx_density.c @@ -119,7 +119,7 @@ int get_electrons(t_electron **eltab, const char *fn) gmx_fatal(FARGS, "Invalid line in datafile at line %d\n", i+1); } (*eltab)[i].nr_el = tempnr; - (*eltab)[i].atomname = strdup(tempname); + (*eltab)[i].atomname = gmx_strdup(tempname); } gmx_ffclose(in); @@ -275,7 +275,7 @@ void calc_electron_density(const char *fn, atom_id **index, int gnx[], slice = (z / (*slWidth)); } sought.nr_el = 0; - sought.atomname = strdup(*(top->atoms.atomname[index[n][i]])); + sought.atomname = gmx_strdup(*(top->atoms.atomname[index[n][i]])); /* now find the number of electrons. This is not efficient. */ found = (t_electron *) diff --git a/src/gromacs/gmxana/gmx_do_dssp.c b/src/gromacs/gmxana/gmx_do_dssp.c index d5642b1b7e..74fd34c1c1 100644 --- a/src/gromacs/gmxana/gmx_do_dssp.c +++ b/src/gromacs/gmxana/gmx_do_dssp.c @@ -212,7 +212,7 @@ static void check_oo(t_atoms *atoms) int i; - OOO = strdup("O"); + OOO = gmx_strdup("O"); for (i = 0; (i < atoms->nr); i++) { @@ -352,7 +352,7 @@ void analyse_ss(const char *outfile, t_matrix *mat, const char *ss_string, leg[0] = "Structure"; for (s = 0; s < (size_t)mat->nmap; s++) { - leg[s+1] = strdup(map[s].desc); + leg[s+1] = gmx_strdup(map[s].desc); } fp = xvgropen(outfile, "Secondary Structure", diff --git a/src/gromacs/gmxana/gmx_energy.c b/src/gromacs/gmxana/gmx_energy.c index 177f4f596b..d120708e24 100644 --- a/src/gromacs/gmxana/gmx_energy.c +++ b/src/gromacs/gmxana/gmx_energy.c @@ -191,7 +191,7 @@ static int *select_by_name(int nre, gmx_enxnm_t *nm, int *nset) j = 0; for (k = 0; k < nre; k++) { - newnm[k] = strdup(nm[k].name); + newnm[k] = gmx_strdup(nm[k].name); /* Insert dashes in all the names */ while ((ptr = strchr(newnm[k], ' ')) != NULL) { @@ -2144,7 +2144,7 @@ int gmx_energy(int argc, char *argv[]) } if (bSum) { - leg[nset] = strdup("Sum"); + leg[nset] = gmx_strdup("Sum"); xvgr_legend(out, nset+1, (const char**)leg, oenv); } else @@ -2281,14 +2281,14 @@ int gmx_energy(int argc, char *argv[]) for (j = 0; j < 3; j++) { sprintf(buf, "eig%d", j+1); - otenleg[(bOvec ? 12 : 3)*i+j] = strdup(buf); + otenleg[(bOvec ? 12 : 3)*i+j] = gmx_strdup(buf); } if (bOvec) { for (j = 0; j < 9; j++) { sprintf(buf, "vec%d%s", j/3+1, j%3 == 0 ? "x" : (j%3 == 1 ? "y" : "z")); - otenleg[12*i+3+j] = strdup(buf); + otenleg[12*i+3+j] = gmx_strdup(buf); } } } diff --git a/src/gromacs/gmxana/gmx_genion.c b/src/gromacs/gmxana/gmx_genion.c index 8558fe866f..64d0a98ff6 100644 --- a/src/gromacs/gmxana/gmx_genion.c +++ b/src/gromacs/gmxana/gmx_genion.c @@ -122,7 +122,7 @@ static char *aname(const char *mname) char *str; int i; - str = strdup(mname); + str = gmx_strdup(mname); i = strlen(str)-1; while (i > 1 && (isdigit(str[i]) || (str[i] == '+') || (str[i] == '-'))) { @@ -176,14 +176,14 @@ void sort_ions(int nsa, int nw, int repl[], atom_id index[], if (np) { snew(pptr, 1); - pptr[0] = strdup(p_name); + pptr[0] = gmx_strdup(p_name); snew(paptr, 1); paptr[0] = aname(p_name); } if (nn) { snew(nptr, 1); - nptr[0] = strdup(n_name); + nptr[0] = gmx_strdup(n_name); snew(naptr, 1); naptr[0] = aname(n_name); } @@ -290,7 +290,7 @@ static void update_topol(const char *topinout, int p_num, int n_num, } /* Store this molecules section line */ srenew(mol_line, nmol_line+1); - mol_line[nmol_line] = strdup(buf); + mol_line[nmol_line] = gmx_strdup(buf); nmol_line++; } } diff --git a/src/gromacs/gmxana/gmx_hbond.c b/src/gromacs/gmxana/gmx_hbond.c index 52f5ec6ca0..07228ef4b1 100644 --- a/src/gromacs/gmxana/gmx_hbond.c +++ b/src/gromacs/gmxana/gmx_hbond.c @@ -4605,7 +4605,7 @@ int gmx_hbond(int argc, char *argv[]) gmx_fatal(FARGS, "Could not initiate t_gemParams params."); } } - gemstring = strdup(gemType[hb->per->gemtype]); + gemstring = gmx_strdup(gemType[hb->per->gemtype]); do_hbac(opt2fn("-ac", NFILE, fnm), hb, nDump, bMerge, bContact, fit_start, temp, r2cut > 0, smooth_tail_start, oenv, gemstring, nThreads, NN, bBallistic, bGemFit); @@ -4745,9 +4745,9 @@ int gmx_hbond(int argc, char *argv[]) if (USE_THIS_GROUP(j) ) { sprintf(buf, "Donors %s", grpnames[j]); - legnames[i++] = strdup(buf); + legnames[i++] = gmx_strdup(buf); sprintf(buf, "Acceptors %s", grpnames[j]); - legnames[i++] = strdup(buf); + legnames[i++] = gmx_strdup(buf); } } if (i != nleg) diff --git a/src/gromacs/gmxana/gmx_make_ndx.c b/src/gromacs/gmxana/gmx_make_ndx.c index cafeb6c7f3..6d1aba949c 100644 --- a/src/gromacs/gmxana/gmx_make_ndx.c +++ b/src/gromacs/gmxana/gmx_make_ndx.c @@ -278,7 +278,7 @@ static gmx_bool parse_string(char **string, int *nr, int ngrps, char **grpname) { c = (*string)[0]; (*string)++; - s = strdup((*string)); + s = gmx_strdup((*string)); sp = strchr(s, c); if (sp != NULL) { @@ -747,7 +747,7 @@ static void remove_group(int nr, int nr2, t_blocka *block, char ***gn) { block->index[i] = block->index[i+1]-shift; } - name = strdup((*gn)[nr]); + name = gmx_strdup((*gn)[nr]); sfree((*gn)[nr]); for (i = nr; i < block->nr-1; i++) { @@ -796,7 +796,7 @@ static void split_group(t_atoms *atoms, int sel_nr, t_blocka *block, char ***gn, { sprintf(buf, "%s_%s_%d", (*gn)[sel_nr], name, atoms->resinfo[resind].nr); } - (*gn)[block->nr-1] = strdup(buf); + (*gn)[block->nr-1] = gmx_strdup(buf); } block->a[block->nra] = a; block->nra++; @@ -887,7 +887,7 @@ static int split_chain(t_atoms *atoms, rvec *x, srenew(block->index, block->nr+1); srenew(*gn, block->nr); sprintf(buf, "%s_chain%d", (*gn)[sel_nr], j+1); - (*gn)[block->nr-1] = strdup(buf); + (*gn)[block->nr-1] = gmx_strdup(buf); for (i = block->index[sel_nr]; i < block->index[sel_nr+1]; i++) { a = block->a[i]; @@ -1330,7 +1330,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha { sscanf(string, "%s", gname); sfree((*gn)[sel_nr]); - (*gn)[sel_nr] = strdup(gname); + (*gn)[sel_nr] = gmx_strdup(gname); } } } @@ -1448,7 +1448,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha copy2block(nr, index, block); srenew(*gn, block->nr); newgroup = block->nr-1; - (*gn)[newgroup] = strdup(gname); + (*gn)[newgroup] = gmx_strdup(gname); } else { diff --git a/src/gromacs/gmxana/gmx_mindist.c b/src/gromacs/gmxana/gmx_mindist.c index 439d19c9d4..63571011f4 100644 --- a/src/gromacs/gmxana/gmx_mindist.c +++ b/src/gromacs/gmxana/gmx_mindist.c @@ -361,7 +361,7 @@ void dist_plot(const char *fn, const char *afile, const char *dfile, { snew(leg, 1); sprintf(buf, "Internal in %s", grpn[0]); - leg[0] = strdup(buf); + leg[0] = gmx_strdup(buf); xvgr_legend(dist, 0, (const char**)leg, oenv); if (num) { @@ -376,7 +376,7 @@ void dist_plot(const char *fn, const char *afile, const char *dfile, for (k = i+1; (k < ng); k++, j++) { sprintf(buf, "%s-%s", grpn[i], grpn[k]); - leg[j] = strdup(buf); + leg[j] = gmx_strdup(buf); } } xvgr_legend(dist, j, (const char**)leg, oenv); @@ -392,7 +392,7 @@ void dist_plot(const char *fn, const char *afile, const char *dfile, for (i = 0; (i < ng-1); i++) { sprintf(buf, "%s-%s", grpn[0], grpn[i+1]); - leg[i] = strdup(buf); + leg[i] = gmx_strdup(buf); } xvgr_legend(dist, ng-1, (const char**)leg, oenv); if (num) diff --git a/src/gromacs/gmxana/gmx_mk_angndx.c b/src/gromacs/gmxana/gmx_mk_angndx.c index 89d60d6509..9a52867969 100644 --- a/src/gromacs/gmxana/gmx_mk_angndx.c +++ b/src/gromacs/gmxana/gmx_mk_angndx.c @@ -129,7 +129,7 @@ static void fill_ft_ind(int nft, int *ft, t_idef *idef, gmx_fatal(FARGS, "Unsupported function type '%s' selected", interaction_function[ftype].longname); } - grpnames[ind] = strdup(buf); + grpnames[ind] = gmx_strdup(buf); ind++; } } diff --git a/src/gromacs/gmxana/gmx_polystat.c b/src/gromacs/gmxana/gmx_polystat.c index 3595fc9eef..bed77c36da 100644 --- a/src/gromacs/gmxana/gmx_polystat.c +++ b/src/gromacs/gmxana/gmx_polystat.c @@ -233,7 +233,7 @@ int gmx_polystat(int argc, char *argv[]) for (d2 = 0; d2 < DIM; d2++) { sprintf(buf, "eig%d %c", d+1, 'x'+d2); - legp[d*DIM+d2] = strdup(buf); + legp[d*DIM+d2] = gmx_strdup(buf); } } xvgr_legend(outv, DIM*DIM, (const char**)legp, oenv); diff --git a/src/gromacs/gmxana/gmx_rmsdist.c b/src/gromacs/gmxana/gmx_rmsdist.c index f3e1038fd1..e5983aa36f 100644 --- a/src/gromacs/gmxana/gmx_rmsdist.c +++ b/src/gromacs/gmxana/gmx_rmsdist.c @@ -186,14 +186,14 @@ static int read_equiv(const char *eq_fn, t_equiv ***equivptr) { lp += n; snew(equiv[neq], 1); - equiv[neq][0].nname = strdup(atomname); + equiv[neq][0].nname = gmx_strdup(atomname); while (sscanf(lp, "%d %s %s %n", &resnr, resname, atomname, &n) == 3) { /* this is not efficient, but I'm lazy (again) */ srenew(equiv[neq], na+1); equiv[neq][na].rnr = resnr-1; - equiv[neq][na].rname = strdup(resname); - equiv[neq][na].aname = strdup(atomname); + equiv[neq][na].rname = gmx_strdup(resname); + equiv[neq][na].aname = gmx_strdup(atomname); if (na > 0) { equiv[neq][na].nname = NULL; @@ -267,7 +267,7 @@ static gmx_bool is_equiv(int neq, t_equiv **equiv, char **nname, } if (bFound) { - *nname = strdup(equiv[i-1][0].nname); + *nname = gmx_strdup(equiv[i-1][0].nname); } return bFound; @@ -318,7 +318,7 @@ static int analyze_noe_equivalent(const char *eq_fn, rnrj, *atoms->resinfo[rnrj].name, *atoms->atomname[index[j]]); if (nnm[i] && bEquiv) { - nnm[j] = strdup(nnm[i]); + nnm[j] = gmx_strdup(nnm[i]); } if (bEquiv) { @@ -399,18 +399,18 @@ static int analyze_noe_equivalent(const char *eq_fn, noe_gr[gi].anr = index[i]; if (nnm[i]) { - noe_gr[gi].aname = strdup(nnm[i]); + noe_gr[gi].aname = gmx_strdup(nnm[i]); } else { - noe_gr[gi].aname = strdup(*atoms->atomname[index[i]]); + noe_gr[gi].aname = gmx_strdup(*atoms->atomname[index[i]]); if (noe_index[i] == noe_index[i+1]) { noe_gr[gi].aname[strlen(noe_gr[gi].aname)-1] = '*'; } } noe_gr[gi].rnr = atoms->atom[index[i]].resind; - noe_gr[gi].rname = strdup(*atoms->resinfo[noe_gr[gi].rnr].name); + noe_gr[gi].rname = gmx_strdup(*atoms->resinfo[noe_gr[gi].rnr].name); /* dump group definitions */ if (debug) { diff --git a/src/gromacs/gmxana/gmx_saltbr.c b/src/gromacs/gmxana/gmx_saltbr.c index adca73302d..46f1c59731 100644 --- a/src/gromacs/gmxana/gmx_saltbr.c +++ b/src/gromacs/gmxana/gmx_saltbr.c @@ -86,7 +86,7 @@ static t_charge *mk_charge(t_atoms *atoms, t_block *cgs, int *nncg) *(atoms->resinfo[resnr].name), atoms->resinfo[resnr].nr, anr+1); - cg[ncg].label = strdup(buf); + cg[ncg].label = gmx_strdup(buf); ncg++; } } diff --git a/src/gromacs/gmxana/gmx_trjcat.c b/src/gromacs/gmxana/gmx_trjcat.c index 9ad5e3fd3b..90bbb779c9 100644 --- a/src/gromacs/gmxana/gmx_trjcat.c +++ b/src/gromacs/gmxana/gmx_trjcat.c @@ -587,7 +587,7 @@ int gmx_trjcat(int argc, char *argv[]) { if (nfile_out != nset) { - char *buf = strdup(fnms_out[0]); + char *buf = gmx_strdup(fnms_out[0]); snew(fnms_out, nset); for (i = 0; (i < nset); i++) { diff --git a/src/gromacs/gmxana/gmx_trjconv.c b/src/gromacs/gmxana/gmx_trjconv.c index dcb57c94f1..d37df65a53 100644 --- a/src/gromacs/gmxana/gmx_trjconv.c +++ b/src/gromacs/gmxana/gmx_trjconv.c @@ -1043,7 +1043,7 @@ int gmx_trjconv(int argc, char *argv[]) { gmx_fatal(FARGS, "Output file name '%s' does not contain a '.'", out_file); } - outf_base = strdup(out_file); + outf_base = gmx_strdup(out_file); outf_base[outf_ext - out_file] = '\0'; } diff --git a/src/gromacs/gmxana/gmx_tune_pme.c b/src/gromacs/gmxana/gmx_tune_pme.c index 3e4f1712f7..d93d597b0e 100644 --- a/src/gromacs/gmxana/gmx_tune_pme.c +++ b/src/gromacs/gmxana/gmx_tune_pme.c @@ -592,25 +592,25 @@ static void get_program_paths(gmx_bool bThreads, char *cmd_mpirun[], char *cmd_m { if ( (cp = getenv("MPIRUN")) != NULL) { - *cmd_mpirun = strdup(cp); + *cmd_mpirun = gmx_strdup(cp); } else { - *cmd_mpirun = strdup(def_mpirun); + *cmd_mpirun = gmx_strdup(def_mpirun); } } else { - *cmd_mpirun = strdup(empty_mpirun); + *cmd_mpirun = gmx_strdup(empty_mpirun); } if ( (cp = getenv("MDRUN" )) != NULL) { - *cmd_mdrun = strdup(cp); + *cmd_mdrun = gmx_strdup(cp); } else { - *cmd_mdrun = strdup(def_mdrun); + *cmd_mdrun = gmx_strdup(def_mdrun); } } diff --git a/src/gromacs/gmxana/gmx_vanhove.c b/src/gromacs/gmxana/gmx_vanhove.c index 253027e0cb..4aa720fdeb 100644 --- a/src/gromacs/gmxana/gmx_vanhove.c +++ b/src/gromacs/gmxana/gmx_vanhove.c @@ -443,7 +443,7 @@ int gmx_vanhove(int argc, char *argv[]) for (fbin = 0; fbin < nr; fbin++) { sprintf(buf, "%g ps", (fbin + 1)*fshift*dt); - legend[fbin] = strdup(buf); + legend[fbin] = gmx_strdup(buf); } xvgr_legend(fp, nr, (const char**)legend, oenv); for (i = 0; i < nalloc; i++) diff --git a/src/gromacs/gmxana/gmx_wham.cpp b/src/gromacs/gmxana/gmx_wham.cpp index a37f2ca503..7a0240a4a2 100644 --- a/src/gromacs/gmxana/gmx_wham.cpp +++ b/src/gromacs/gmxana/gmx_wham.cpp @@ -1453,7 +1453,7 @@ void print_histograms(const char *fnhist, t_UmbrellaWindow * window, int nWindow } else { - fn = strdup(fnhist); + fn = gmx_strdup(fnhist); strcpy(title, "Umbrella histograms"); } diff --git a/src/gromacs/gmxana/gmx_wheel.c b/src/gromacs/gmxana/gmx_wheel.c index 170c668cb7..d518991015 100644 --- a/src/gromacs/gmxana/gmx_wheel.c +++ b/src/gromacs/gmxana/gmx_wheel.c @@ -50,6 +50,7 @@ #include "gmx_ana.h" #include "gromacs/commandline/pargs.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/futil.h" #include "gromacs/fileio/strdb.h" #include "gromacs/fileio/writeps.h" @@ -264,7 +265,7 @@ int gmx_wheel(int argc, char *argv[]) } else if (strcmp(argv[i], "-T") == 0) { - title = strdup(argv[++i]); + title = gmx_strdup(argv[++i]); fprintf(stderr, "Title will be '%s'\n", title); } else if (strcmp(argv[i], "-nn") == 0) diff --git a/src/gromacs/gmxana/gmx_xpm2ps.c b/src/gromacs/gmxana/gmx_xpm2ps.c index 449a1b792c..caca09b2b7 100644 --- a/src/gromacs/gmxana/gmx_xpm2ps.c +++ b/src/gromacs/gmxana/gmx_xpm2ps.c @@ -398,7 +398,7 @@ static void draw_boxes(t_psdata ps, real x0, real y0, real w, for (j = 0; (j < ntx); j++) { sprintf(buf, "%g", mat[i].axis_x[j]); - xtick[j] = strdup(buf); + xtick[j] = gmx_strdup(buf); } ps_strfont(ps, psr->X.tickfont, psr->X.tickfontsize); for (x = 0; (x < ntx); x++) @@ -435,7 +435,7 @@ static void draw_boxes(t_psdata ps, real x0, real y0, real w, for (j = 0; (j < nty); j++) { sprintf(buf, "%g", mat[i].axis_y[j]); - ytick[j] = strdup(buf); + ytick[j] = gmx_strdup(buf); } for (y = 0; (y < nty); y++) diff --git a/src/gromacs/gmxana/nrama.c b/src/gromacs/gmxana/nrama.c index db6e0d7510..c977418324 100644 --- a/src/gromacs/gmxana/nrama.c +++ b/src/gromacs/gmxana/nrama.c @@ -142,7 +142,7 @@ static void add_xr(t_xrama *xr, int ff[5], t_atoms *atoms) xr->pp[xr->npp].bShow = FALSE; sprintf(buf, "%s-%d", *atoms->resinfo[atoms->atom[ff[1]].resind].name, atoms->resinfo[atoms->atom[ff[1]].resind].nr); - xr->pp[xr->npp].label = strdup(buf); + xr->pp[xr->npp].label = gmx_strdup(buf); xr->npp++; } diff --git a/src/gromacs/gmxana/nsfactor.c b/src/gromacs/gmxana/nsfactor.c index d53a162fa8..c8e70dd921 100644 --- a/src/gromacs/gmxana/nsfactor.c +++ b/src/gromacs/gmxana/nsfactor.c @@ -115,7 +115,7 @@ gmx_neutron_atomic_structurefactors_t *gmx_neutronstructurefactors_init(const ch i = line_no; if (sscanf(line, "%s %d %d %lf", atomnm, &p, &n, &slength) == 4) { - gnsf->atomnm[i] = strdup(atomnm); + gnsf->atomnm[i] = gmx_strdup(atomnm); gnsf->n[i] = n; gnsf->p[i] = p; gnsf->slength[i] = slength; diff --git a/src/gromacs/gmxana/sfactor.c b/src/gromacs/gmxana/sfactor.c index a074fbc1b0..5da3cfcb2e 100644 --- a/src/gromacs/gmxana/sfactor.c +++ b/src/gromacs/gmxana/sfactor.c @@ -282,7 +282,7 @@ extern gmx_structurefactors_t *gmx_structurefactors_init(const char *datfn) if (sscanf(line, "%s %d %lf %lf %lf %lf %lf %lf %lf %lf %lf", atomn, &p, &a1, &a2, &a3, &a4, &b1, &b2, &b3, &b4, &c) == 11) { - gsf->atomnm[i] = strdup(atomn); + gsf->atomnm[i] = gmx_strdup(atomn); gsf->p[i] = p; snew(gsf->a[i], 4); snew(gsf->b[i], 4); diff --git a/src/gromacs/gmxlib/readinp.c b/src/gromacs/gmxlib/readinp.c index da6b014de9..5e4dfc9c10 100644 --- a/src/gromacs/gmxlib/readinp.c +++ b/src/gromacs/gmxlib/readinp.c @@ -168,8 +168,8 @@ t_inpfile *read_inpfile(const char *fn, int *ninp, inp[nin-1].count = 0; inp[nin-1].bObsolete = FALSE; inp[nin-1].bSet = FALSE; - inp[nin-1].name = strdup(lbuf); - inp[nin-1].value = strdup(rbuf); + inp[nin-1].name = gmx_strdup(lbuf); + inp[nin-1].value = gmx_strdup(rbuf); } else { @@ -184,7 +184,7 @@ t_inpfile *read_inpfile(const char *fn, int *ninp, { /* override */ sfree(inp[found_index].value); - inp[found_index].value = strdup(rbuf); + inp[found_index].value = gmx_strdup(rbuf); sprintf(warn_buf, "Overriding existing parameter \"%s\" with value \"%s\"\n", lbuf, rbuf); @@ -294,7 +294,7 @@ void replace_inp_entry(int ninp, t_inpfile *inp, const char *old_entry, const ch fprintf(stderr, "Replacing old mdp entry '%s' by '%s'\n", inp[i].name, new_entry); sfree(inp[i].name); - inp[i].name = strdup(new_entry); + inp[i].name = gmx_strdup(new_entry); } else { @@ -342,7 +342,7 @@ static int get_einp(int *ninp, t_inpfile **inp, const char *name) notfound = TRUE; i = (*ninp)++; srenew(*inp, (*ninp)); - (*inp)[i].name = strdup(name); + (*inp)[i].name = gmx_strdup(name); (*inp)[i].bSet = TRUE; } (*inp)[i].count = (*inp)[0].inp_count++; @@ -375,7 +375,7 @@ int get_eint(int *ninp, t_inpfile **inp, const char *name, int def, if (ii == -1) { sprintf(buf, "%d", def); - (*inp)[(*ninp)-1].value = strdup(buf); + (*inp)[(*ninp)-1].value = gmx_strdup(buf); return def; } @@ -405,7 +405,7 @@ gmx_int64_t get_eint64(int *ninp, t_inpfile **inp, if (ii == -1) { sprintf(buf, "%"GMX_PRId64, def); - (*inp)[(*ninp)-1].value = strdup(buf); + (*inp)[(*ninp)-1].value = gmx_strdup(buf); return def; } @@ -434,7 +434,7 @@ double get_ereal(int *ninp, t_inpfile **inp, const char *name, double def, if (ii == -1) { sprintf(buf, "%g", def); - (*inp)[(*ninp)-1].value = strdup(buf); + (*inp)[(*ninp)-1].value = gmx_strdup(buf); return def; } @@ -463,7 +463,7 @@ const char *get_estr(int *ninp, t_inpfile **inp, const char *name, const char *d if (def) { sprintf(buf, "%s", def); - (*inp)[(*ninp)-1].value = strdup(buf); + (*inp)[(*ninp)-1].value = gmx_strdup(buf); } else { @@ -489,7 +489,7 @@ int get_eeenum(int *ninp, t_inpfile **inp, const char *name, const char **defs, if (ii == -1) { - (*inp)[(*ninp)-1].value = strdup(defs[0]); + (*inp)[(*ninp)-1].value = gmx_strdup(defs[0]); return 0; } @@ -522,7 +522,7 @@ int get_eeenum(int *ninp, t_inpfile **inp, const char *name, const char **defs, fprintf(stderr, "%s\n", buf); } - (*inp)[ii].value = strdup(defs[0]); + (*inp)[ii].value = gmx_strdup(defs[0]); return 0; } diff --git a/src/gromacs/gmxpreprocess/fflibutil.cpp b/src/gromacs/gmxpreprocess/fflibutil.cpp index 1c2d368216..c2cbdf488c 100644 --- a/src/gromacs/gmxpreprocess/fflibutil.cpp +++ b/src/gromacs/gmxpreprocess/fflibutil.cpp @@ -200,7 +200,7 @@ static int low_fflib_search_file_end(const char *ffdir, sprintf(fn_dir, "%s%c%s", dir, DIR_SEPARATOR, nextname); /* Copy the file name, possibly including the path. */ - fns[n] = strdup(fn_dir); + fns[n] = gmx_strdup(fn_dir); if (ffdir == NULL) { @@ -213,11 +213,11 @@ static int low_fflib_search_file_end(const char *ffdir, srenew(fns_short, n+1); if (strcmp(dir, ".") == 0 || bEnvIsSet) { - fns_short[n] = strdup(fn_dir); + fns_short[n] = gmx_strdup(fn_dir); } else { - fns_short[n] = strdup(nextname); + fns_short[n] = gmx_strdup(nextname); } } n++; @@ -293,7 +293,7 @@ int fflib_search_file_in_dirend(const char *filename, const char *dirend, { /* We have a match */ srenew(dns, n+1); - dns[n] = strdup(f_short[i]); + dns[n] = gmx_strdup(f_short[i]); n++; } } diff --git a/src/gromacs/gmxpreprocess/genhydro.c b/src/gromacs/gmxpreprocess/genhydro.c index 238a3db480..4ca92aa373 100644 --- a/src/gromacs/gmxpreprocess/genhydro.c +++ b/src/gromacs/gmxpreprocess/genhydro.c @@ -52,6 +52,7 @@ #include "network.h" #include "gromacs/topology/symtab.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/smalloc.h" @@ -59,7 +60,7 @@ static void copy_atom(t_atoms *atoms1, int a1, t_atoms *atoms2, int a2) { atoms2->atom[a2] = atoms1->atom[a1]; snew(atoms2->atomname[a2], 1); - *atoms2->atomname[a2] = strdup(*atoms1->atomname[a1]); + *atoms2->atomname[a2] = gmx_strdup(*atoms1->atomname[a1]); } static atom_id pdbasearch_atom(const char *name, int resind, t_atoms *pdba, @@ -165,7 +166,7 @@ static t_hackblock *get_hackblocks(t_atoms *pdba, int nah, t_hackblock ah[], { if (hb[rnr].name == NULL) { - hb[rnr].name = strdup(ahptr->name); + hb[rnr].name = gmx_strdup(ahptr->name); } merge_hacks(ahptr, &hb[rnr]); } @@ -230,7 +231,7 @@ static void expand_hackblocks_one(t_hackblock *hbr, char *atomname, { if ( (*abi)[*nabi + k].oname == NULL) { - (*abi)[*nabi + k].nname = strdup(atomname); + (*abi)[*nabi + k].nname = gmx_strdup(atomname); (*abi)[*nabi + k].nname[0] = 'H'; } } @@ -244,7 +245,7 @@ static void expand_hackblocks_one(t_hackblock *hbr, char *atomname, (*abi)[*nabi + k].oname ? (*abi)[*nabi + k].oname : ""); } sfree((*abi)[*nabi + k].nname); - (*abi)[*nabi + k].nname = strdup(hbr->hack[j].nname); + (*abi)[*nabi + k].nname = gmx_strdup(hbr->hack[j].nname); } if (hbr->hack[j].tp == 10 && k == 2) @@ -665,7 +666,7 @@ static int add_h_low(t_atoms **pdbaptr, rvec *xptr[], ab[i][j].nname); } snew(newpdba->atomname[newi], 1); - *newpdba->atomname[newi] = strdup(ab[i][j].nname); + *newpdba->atomname[newi] = gmx_strdup(ab[i][j].nname); if (ab[i][j].oname != NULL && ab[i][j].atom) /* replace */ { /* newpdba->atom[newi].m = ab[i][j].atom->m; */ /* newpdba->atom[newi].q = ab[i][j].atom->q; */ diff --git a/src/gromacs/gmxpreprocess/gmxcpp.c b/src/gromacs/gmxpreprocess/gmxcpp.c index 87361b3526..92133a60ef 100644 --- a/src/gromacs/gmxpreprocess/gmxcpp.c +++ b/src/gromacs/gmxpreprocess/gmxcpp.c @@ -167,7 +167,7 @@ static void add_include(const char *include) { nincl++; srenew(incl, nincl); - incl[nincl-1] = strdup(include); + incl[nincl-1] = gmx_strdup(include); } } @@ -199,7 +199,7 @@ static void add_define(const char *name, const char *value) ndef++; srenew(defs, ndef); i = ndef - 1; - defs[i].name = strdup(name); + defs[i].name = gmx_strdup(name); } else if (defs[i].def) { @@ -211,7 +211,7 @@ static void add_define(const char *name, const char *value) } if (value && strlen(value) > 0) { - defs[i].def = strdup(value); + defs[i].def = gmx_strdup(value); } else { @@ -282,7 +282,7 @@ int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts) /* Find the file. First check whether it is in the current directory. */ if (gmx_fexist(filenm)) { - cpp->fn = strdup(filenm); + cpp->fn = gmx_strdup(filenm); } else { @@ -332,7 +332,7 @@ int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts) { cpp->path = cpp->fn; *ptr = '\0'; - cpp->fn = strdup(ptr+1); + cpp->fn = gmx_strdup(ptr+1); snew(cpp->cwd, STRLEN); gmx_getcwd(cpp->cwd, STRLEN); @@ -807,5 +807,5 @@ char *cpp_error(gmx_cpp_t *handlep, int status) (handle) ? handle->line_nr : -1, handle->line ? handle->line : ""); - return strdup(buf); + return gmx_strdup(buf); } diff --git a/src/gromacs/gmxpreprocess/h_db.c b/src/gromacs/gmxpreprocess/h_db.c index 8c54c5679c..6768e8d81a 100644 --- a/src/gromacs/gmxpreprocess/h_db.c +++ b/src/gromacs/gmxpreprocess/h_db.c @@ -108,14 +108,14 @@ void read_ab(char *line, const char *fn, t_hack *hack) } for (i = 0; (i < hack->nctl); i++) { - hack->a[i] = strdup(a[i]); + hack->a[i] = gmx_strdup(a[i]); } for (; i < 4; i++) { hack->a[i] = NULL; } hack->oname = NULL; - hack->nname = strdup(hn); + hack->nname = gmx_strdup(hn); hack->atom = NULL; hack->cgnr = NOTSET; hack->bXSet = FALSE; @@ -161,8 +161,8 @@ static void read_h_db_file(const char *hfn, int *nahptr, t_hackblock **ah) } srenew(aah, nah+1); clear_t_hackblock(&aah[nah]); - aah[nah].name = strdup(buf); - aah[nah].filebase = strdup(filebase); + aah[nah].name = gmx_strdup(buf); + aah[nah].filebase = gmx_strdup(filebase); if (sscanf(line+n, "%d", &nab) == 1) { diff --git a/src/gromacs/gmxpreprocess/hackblock.c b/src/gromacs/gmxpreprocess/hackblock.c index dc7b66a6ad..4afed71dd2 100644 --- a/src/gromacs/gmxpreprocess/hackblock.c +++ b/src/gromacs/gmxpreprocess/hackblock.c @@ -39,6 +39,7 @@ #include #include "hackblock.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/smalloc.h" #include "gromacs/math/vec.h" #include "names.h" @@ -164,7 +165,7 @@ void clear_t_hack(t_hack *hack) } } -#define safe_strdup(str) ((str != NULL) ? strdup(str) : NULL) +#define safe_strdup(str) ((str != NULL) ? gmx_strdup(str) : NULL) static void copy_t_rbonded(t_rbonded *s, t_rbonded *d) { diff --git a/src/gromacs/gmxpreprocess/hizzie.c b/src/gromacs/gmxpreprocess/hizzie.c index 6a71763a5a..99c1ca9232 100644 --- a/src/gromacs/gmxpreprocess/hizzie.c +++ b/src/gromacs/gmxpreprocess/hizzie.c @@ -348,7 +348,7 @@ void set_histp(t_atoms *pdba, rvec *x, real angle, real dist) } snew(pdba->resinfo[hisind].rtp, 1); - *pdba->resinfo[hisind].rtp = strdup(hh[type]); + *pdba->resinfo[hisind].rtp = gmx_strdup(hh[type]); } } } diff --git a/src/gromacs/gmxpreprocess/nm2type.c b/src/gromacs/gmxpreprocess/nm2type.c index e065e9e846..5a4bec6381 100644 --- a/src/gromacs/gmxpreprocess/nm2type.c +++ b/src/gromacs/gmxpreprocess/nm2type.c @@ -105,7 +105,7 @@ static void rd_nm2type_file(const char *fn, int *nnm, t_nm2type **nmp) { gmx_fatal(FARGS, "Error on line %d of %s", line, libfilename); } - newbuf[i] = strdup(nbbuf); + newbuf[i] = gmx_strdup(nbbuf); strcat(format, "%*s%*s"); } } @@ -113,8 +113,8 @@ static void rd_nm2type_file(const char *fn, int *nnm, t_nm2type **nmp) { newbuf = NULL; } - nm2t[nnnm].elem = strdup(elem); - nm2t[nnnm].type = strdup(type); + nm2t[nnnm].elem = gmx_strdup(elem); + nm2t[nnnm].type = gmx_strdup(type); nm2t[nnnm].q = qq; nm2t[nnnm].m = mm; nm2t[nnnm].nbonds = nb; diff --git a/src/gromacs/gmxpreprocess/pdb2gmx.c b/src/gromacs/gmxpreprocess/pdb2gmx.c index f165d723cc..9e64f5c994 100644 --- a/src/gromacs/gmxpreprocess/pdb2gmx.c +++ b/src/gromacs/gmxpreprocess/pdb2gmx.c @@ -1682,7 +1682,7 @@ int gmx_pdb2gmx(int argc, char *argv[]) chains[i].pdba->atom[j] = pdba_all.atom[pdb_ch[si].start+j]; snew(chains[i].pdba->atomname[j], 1); *chains[i].pdba->atomname[j] = - strdup(*pdba_all.atomname[pdb_ch[si].start+j]); + gmx_strdup(*pdba_all.atomname[pdb_ch[si].start+j]); chains[i].pdba->pdbinfo[j] = pdba_all.pdbinfo[pdb_ch[si].start+j]; copy_rvec(pdbx[pdb_ch[si].start+j], chains[i].x[j]); } @@ -1699,7 +1699,7 @@ int gmx_pdb2gmx(int argc, char *argv[]) { chains[i].pdba->resinfo[j] = pdba_all.resinfo[k+j]; snew(chains[i].pdba->resinfo[j].name, 1); - *chains[i].pdba->resinfo[j].name = strdup(*pdba_all.resinfo[k+j].name); + *chains[i].pdba->resinfo[j].name = gmx_strdup(*pdba_all.resinfo[k+j].name); /* make all chain identifiers equal to that of the chain */ chains[i].pdba->resinfo[j].chainid = pdb_ch[si].chainid; } @@ -2057,7 +2057,7 @@ int gmx_pdb2gmx(int argc, char *argv[]) nincl++; srenew(incls, nincl); - incls[nincl-1] = strdup(itp_fn); + incls[nincl-1] = gmx_strdup(itp_fn); itp_file = gmx_fio_fopen(itp_fn, "w"); } else @@ -2068,12 +2068,12 @@ int gmx_pdb2gmx(int argc, char *argv[]) srenew(mols, nmol+1); if (cc->bAllWat) { - mols[nmol].name = strdup("SOL"); + mols[nmol].name = gmx_strdup("SOL"); mols[nmol].nr = pdba->nres; } else { - mols[nmol].name = strdup(molname); + mols[nmol].name = gmx_strdup(molname); mols[nmol].nr = 1; } nmol++; diff --git a/src/gromacs/gmxpreprocess/pdb2top.cpp b/src/gromacs/gmxpreprocess/pdb2top.cpp index 8f4a126381..739dce9f15 100644 --- a/src/gromacs/gmxpreprocess/pdb2top.cpp +++ b/src/gromacs/gmxpreprocess/pdb2top.cpp @@ -172,7 +172,7 @@ choose_ff(const char *ffsel, ptr = strrchr(ffdirs[i], '/'); if (ptr == NULL) { - ffs[i] = strdup(ffdirs[i]); + ffs[i] = gmx_strdup(ffdirs[i]); ffs_dir[i] = low_gmxlibfn(ffdirs[i], FALSE, FALSE); if (ffs_dir[i] == NULL) { @@ -181,8 +181,8 @@ choose_ff(const char *ffsel, } else { - ffs[i] = strdup(ptr+1); - ffs_dir[i] = strdup(ffdirs[i]); + ffs[i] = gmx_strdup(ptr+1); + ffs_dir[i] = gmx_strdup(ffdirs[i]); } ffs_dir[i][strlen(ffs_dir[i])-strlen(ffs[i])-1] = '\0'; /* Remove the extension from the ffdir name */ @@ -254,7 +254,7 @@ choose_ff(const char *ffsel, } else { - desc[i] = strdup(ffs[i]); + desc[i] = gmx_strdup(ffs[i]); } } /* Order force fields from the same dir alphabetically @@ -371,7 +371,7 @@ void choose_watermodel(const char *wmsel, const char *ffdir, } else if (strcmp(wmsel, "select") != 0) { - *watermodel = strdup(wmsel); + *watermodel = gmx_strdup(wmsel); return; } @@ -429,7 +429,7 @@ void choose_watermodel(const char *wmsel, const char *ffdir, } else { - *watermodel = strdup(model[sel]); + *watermodel = gmx_strdup(model[sel]); } for (i = 0; i < nwm; i++) @@ -1000,7 +1000,7 @@ void add_atom_to_restp(t_restp *restp, int at_start, const t_hack *hack) } snew( restp->atomname[at_start+1+k], 1); restp->atom [at_start+1+k] = *hack->atom; - *restp->atomname[at_start+1+k] = strdup(buf); + *restp->atomname[at_start+1+k] = gmx_strdup(buf); if (hack->cgnr != NOTSET) { restp->cgnr [at_start+1+k] = hack->cgnr; @@ -1174,7 +1174,7 @@ void get_hackblocks_rtp(t_hackblock **hb, t_restp **restp, } snew( (*restp)[i].atomname[l], 1); (*restp)[i].atom[l] = *(*hb)[i].hack[j].atom; - *(*restp)[i].atomname[l] = strdup((*hb)[i].hack[j].nname); + *(*restp)[i].atomname[l] = gmx_strdup((*hb)[i].hack[j].nname); if ( (*hb)[i].hack[j].cgnr != NOTSET) { (*restp)[i].cgnr [l] = (*hb)[i].hack[j].cgnr; @@ -1331,7 +1331,7 @@ static gmx_bool match_atomnames_with_rtp_atom(t_atoms *pdba, rvec *x, int atind, } /* Rename the atom in pdba */ snew(pdba->atomname[atind], 1); - *pdba->atomname[atind] = strdup(newnm); + *pdba->atomname[atind] = gmx_strdup(newnm); } else if (hbr->hack[j].oname != NULL && hbr->hack[j].nname == NULL && gmx_strcasecmp(oldnm, hbr->hack[j].oname) == 0) diff --git a/src/gromacs/gmxpreprocess/readir.c b/src/gromacs/gmxpreprocess/readir.c index 445d8a6772..f58a75b001 100644 --- a/src/gromacs/gmxpreprocess/readir.c +++ b/src/gromacs/gmxpreprocess/readir.c @@ -1420,7 +1420,7 @@ int str_nelem(const char *str, int maxptr, char *ptr[]) int np = 0; char *copy0, *copy; - copy0 = strdup(str); + copy0 = gmx_strdup(str); copy = copy0; ltrim(copy); while (*copy != '\0') @@ -1675,7 +1675,7 @@ static void do_wall_params(t_inputrec *ir, } for (i = 0; i < ir->nwall; i++) { - opts->wall_atomtype[i] = strdup(names[i]); + opts->wall_atomtype[i] = gmx_strdup(names[i]); } if (ir->wall_type == ewt93 || ir->wall_type == ewt104) @@ -2338,7 +2338,7 @@ void get_ir(const char *mdparin, const char *mdparout, { if (ir->efep != efepNO) { - opts->couple_moltype = strdup(is->couple_moltype); + opts->couple_moltype = gmx_strdup(is->couple_moltype); if (opts->couple_lam0 == opts->couple_lam1) { warning(wi, "The lambda=0 and lambda=1 states for coupling are identical"); @@ -2930,7 +2930,7 @@ static void decode_cos(char *s, t_cosines *cosine) double a, phi; int i; - t = strdup(s); + t = gmx_strdup(s); trim(t); cosine->n = 0; diff --git a/src/gromacs/gmxpreprocess/resall.c b/src/gromacs/gmxpreprocess/resall.c index 14e556a8e2..51d9eec7fc 100644 --- a/src/gromacs/gmxpreprocess/resall.c +++ b/src/gromacs/gmxpreprocess/resall.c @@ -193,7 +193,7 @@ gmx_bool read_bondeds(int bt, FILE *in, char *line, t_restp *rtp) { if (sscanf(line+n, "%s%n", str, &ni) == 1) { - rtp->rb[bt].b[rtp->rb[bt].nb].a[j] = strdup(str); + rtp->rb[bt].b[rtp->rb[bt].nb].a[j] = gmx_strdup(str); } else { @@ -210,7 +210,7 @@ gmx_bool read_bondeds(int bt, FILE *in, char *line, t_restp *rtp) n++; } rtrim(line+n); - rtp->rb[bt].b[rtp->rb[bt].nb].s = strdup(line+n); + rtp->rb[bt].b[rtp->rb[bt].nb].s = gmx_strdup(line+n); rtp->rb[bt].nb++; } /* give back unused memory */ @@ -450,8 +450,8 @@ void read_resall(char *rrdb, int *nrtpptr, t_restp **rtp, { gmx_fatal(FARGS, "in .rtp file at line:\n%s\n", line); } - rrtp[nrtp].resname = strdup(header); - rrtp[nrtp].filebase = strdup(filebase); + rrtp[nrtp].resname = gmx_strdup(header); + rrtp[nrtp].filebase = gmx_strdup(filebase); get_a_line(in, line, STRLEN); bError = FALSE; diff --git a/src/gromacs/gmxpreprocess/specbond.c b/src/gromacs/gmxpreprocess/specbond.c index 5fe81a7d71..08ab832498 100644 --- a/src/gromacs/gmxpreprocess/specbond.c +++ b/src/gromacs/gmxpreprocess/specbond.c @@ -90,12 +90,12 @@ t_specbond *get_specbonds(int *nspecbond) } else { - sb[n].res1 = strdup(r1buf); - sb[n].res2 = strdup(r2buf); - sb[n].newres1 = strdup(nr1buf); - sb[n].newres2 = strdup(nr2buf); - sb[n].atom1 = strdup(a1buf); - sb[n].atom2 = strdup(a2buf); + sb[n].res1 = gmx_strdup(r1buf); + sb[n].res2 = gmx_strdup(r2buf); + sb[n].newres1 = gmx_strdup(nr1buf); + sb[n].newres2 = gmx_strdup(nr2buf); + sb[n].atom1 = gmx_strdup(a1buf); + sb[n].atom2 = gmx_strdup(a2buf); sb[n].nbond1 = nb1; sb[n].nbond2 = nb2; sb[n].length = length; @@ -217,7 +217,7 @@ static void rename_1res(t_atoms *pdba, int resind, char *newres, gmx_bool bVerbo } /* this used to free *resname, which messes up the symtab! */ snew(pdba->resinfo[resind].rtp, 1); - *pdba->resinfo[resind].rtp = strdup(newres); + *pdba->resinfo[resind].rtp = gmx_strdup(newres); } int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, @@ -346,8 +346,8 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, /* Store the residue numbers in the bonds array */ bonds[nbonds].res1 = specp[i]; bonds[nbonds].res2 = specp[j]; - bonds[nbonds].a1 = strdup(*pdba->atomname[ai]); - bonds[nbonds].a2 = strdup(*pdba->atomname[aj]); + bonds[nbonds].a1 = gmx_strdup(*pdba->atomname[ai]); + bonds[nbonds].a2 = gmx_strdup(*pdba->atomname[aj]); /* rename residues */ if (bSwap) { diff --git a/src/gromacs/gmxpreprocess/ter_db.c b/src/gromacs/gmxpreprocess/ter_db.c index 5c35580e08..d5ad310cdb 100644 --- a/src/gromacs/gmxpreprocess/ter_db.c +++ b/src/gromacs/gmxpreprocess/ter_db.c @@ -118,7 +118,7 @@ static void read_atom(char *line, gmx_bool bAdd, { if (nr == 4) { - *nname = strdup(buf[i++]); + *nname = gmx_strdup(buf[i++]); } else { @@ -288,8 +288,8 @@ static void read_ter_db_file(char *fn, srenew(tb, maxnb); } clear_t_hackblock(&tb[nb]); - tb[nb].name = strdup(header); - tb[nb].filebase = strdup(filebase); + tb[nb].name = gmx_strdup(header); + tb[nb].filebase = gmx_strdup(filebase); } } else @@ -327,7 +327,7 @@ static void read_ter_db_file(char *fn, gmx_fatal(FARGS, "Reading Termini Database '%s': " "expected atom name on line\n%s", fn, line); } - tb[nb].hack[nh].oname = strdup(buf); + tb[nb].hack[nh].oname = gmx_strdup(buf); /* we only replace or delete one atom at a time */ tb[nb].hack[nh].nr = 1; } @@ -351,7 +351,7 @@ static void read_ter_db_file(char *fn, { if (tb[nb].hack[nh].oname != NULL) { - tb[nb].hack[nh].nname = strdup(tb[nb].hack[nh].oname); + tb[nb].hack[nh].nname = gmx_strdup(tb[nb].hack[nh].oname); } else { @@ -369,7 +369,7 @@ static void read_ter_db_file(char *fn, { if (sscanf(line+n, "%s%n", buf, &ni) == 1) { - tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = strdup(buf); + tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = gmx_strdup(buf); } else { @@ -383,7 +383,7 @@ static void read_ter_db_file(char *fn, } strcpy(buf, ""); sscanf(line+n, "%s", buf); - tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].s = strdup(buf); + tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].s = gmx_strdup(buf); tb[nb].rb[kwnr].nb++; } else diff --git a/src/gromacs/gmxpreprocess/tomorse.c b/src/gromacs/gmxpreprocess/tomorse.c index 1cb0f55f5b..b6b4baf3f2 100644 --- a/src/gromacs/gmxpreprocess/tomorse.c +++ b/src/gromacs/gmxpreprocess/tomorse.c @@ -84,8 +84,8 @@ static t_2morse *read_dissociation_energies(int *n2morse) srenew(t2m, maxn2m); } /* Copy the values */ - t2m[n2m].ai = strdup(ai); - t2m[n2m].aj = strdup(aj); + t2m[n2m].ai = gmx_strdup(ai); + t2m[n2m].aj = gmx_strdup(aj); t2m[n2m].e_diss = e_diss; /* Increment counter */ n2m++; diff --git a/src/gromacs/gmxpreprocess/topio.c b/src/gromacs/gmxpreprocess/topio.c index 1fc240d6a5..db8073b1c1 100644 --- a/src/gromacs/gmxpreprocess/topio.c +++ b/src/gromacs/gmxpreprocess/topio.c @@ -337,7 +337,7 @@ static char ** cpp_opts(const char *define, const char *include, else { srenew(cppopts, ++ncppopts); - cppopts[ncppopts-1] = strdup(buf); + cppopts[ncppopts-1] = gmx_strdup(buf); } sfree(buf); ptr = rptr; @@ -640,7 +640,7 @@ static char **read_topol(const char *infile, const char *outfile, set_warning_line(wi, cpp_cur_file(&handle), cpp_cur_linenr(&handle)); - pline = strdup(line); + pline = gmx_strdup(line); /* Strip trailing '\' from pline, if it exists */ sl = strlen(pline); @@ -658,7 +658,7 @@ static char **read_topol(const char *infile, const char *outfile, /* Since we depend on the '\' being present to continue to read, we copy line * to a tmp string, strip the '\' from that string, and cat it to pline */ - tmp_line = strdup(line); + tmp_line = gmx_strdup(line); sl = strlen(tmp_line); if ((sl > 0) && (tmp_line[sl-1] == CONTINUE)) @@ -697,7 +697,7 @@ static char **read_topol(const char *infile, const char *outfile, * without the brackets into dirstr, then * skip spaces and tabs on either side of directive */ - dirstr = strdup((pline+1)); + dirstr = gmx_strdup((pline+1)); if ((dummy2 = strchr (dirstr, CLOSEDIR)) != NULL) { (*dummy2) = 0; diff --git a/src/gromacs/gmxpreprocess/x2top.c b/src/gromacs/gmxpreprocess/x2top.c index 085e4c84ef..d9e3a69d19 100644 --- a/src/gromacs/gmxpreprocess/x2top.c +++ b/src/gromacs/gmxpreprocess/x2top.c @@ -538,7 +538,7 @@ int gmx_x2top(int argc, char *argv[]) bOPLS = (strcmp(forcefield, "oplsaa") == 0); - mymol.name = strdup(molnm); + mymol.name = gmx_strdup(molnm); mymol.nr = 1; /* Init parameter lists */ diff --git a/src/gromacs/gmxpreprocess/xlate.c b/src/gromacs/gmxpreprocess/xlate.c index 2e55f750fa..9b728a1b73 100644 --- a/src/gromacs/gmxpreprocess/xlate.c +++ b/src/gromacs/gmxpreprocess/xlate.c @@ -90,12 +90,12 @@ static void get_xlatoms(const char *fn, FILE *fp, } srenew(xl, n+1); - xl[n].filebase = strdup(filebase); + xl[n].filebase = gmx_strdup(filebase); /* Use wildcards... */ if (strcmp(rbuf, "*") != 0) { - xl[n].res = strdup(rbuf); + xl[n].res = gmx_strdup(rbuf); } else { @@ -108,8 +108,8 @@ static void get_xlatoms(const char *fn, FILE *fp, *_ptr = ' '; } - xl[n].atom = strdup(abuf); - xl[n].replace = strdup(repbuf); + xl[n].atom = gmx_strdup(abuf); + xl[n].replace = gmx_strdup(repbuf); n++; } @@ -237,7 +237,7 @@ void rename_atoms(const char *xlfile, const char *ffdir, /* Don't free the old atomname, * since it might be in the symtab. */ - ptr0 = strdup(xlatom[i].replace); + ptr0 = gmx_strdup(xlatom[i].replace); if (bVerbose) { printf("Renaming atom '%s' in residue %d %s to '%s'\n", diff --git a/src/gromacs/mdlib/ebin.c b/src/gromacs/mdlib/ebin.c index e7ec3c72d2..592c824932 100644 --- a/src/gromacs/mdlib/ebin.c +++ b/src/gromacs/mdlib/ebin.c @@ -75,10 +75,10 @@ int get_ebin_space(t_ebin *eb, int nener, const char *enm[], const char *unit) eb->e_sim[i].e = 0; eb->e_sim[i].eav = 0; eb->e_sim[i].esum = 0; - eb->enm[i].name = strdup(enm[i-index]); + eb->enm[i].name = gmx_strdup(enm[i-index]); if (unit != NULL) { - eb->enm[i].unit = strdup(unit); + eb->enm[i].unit = gmx_strdup(unit); } else { @@ -105,7 +105,7 @@ int get_ebin_space(t_ebin *eb, int nener, const char *enm[], const char *unit) } } } - eb->enm[i].unit = strdup(u); + eb->enm[i].unit = gmx_strdup(u); } } @@ -274,7 +274,7 @@ int main(int argc, char *argv[]) { e[i] = i; sprintf(buf, "e%d", i); - ce[i] = strdup(buf); + ce[i] = gmx_strdup(buf); } ie = get_ebin_space(eb, NE, ce); add_ebin(eb, ie, NE, e, 0); @@ -282,7 +282,7 @@ int main(int argc, char *argv[]) { s[i] = i; sprintf(buf, "s%d", i); - cs[i] = strdup(buf); + cs[i] = gmx_strdup(buf); } is = get_ebin_space(eb, NS, cs); add_ebin(eb, is, NS, s, 0); @@ -290,7 +290,7 @@ int main(int argc, char *argv[]) { t[i] = i; sprintf(buf, "t%d", i); - ct[i] = strdup(buf); + ct[i] = gmx_strdup(buf); } it = get_ebin_space(eb, NT, ct); add_ebin(eb, it, NT, t, 0); diff --git a/src/gromacs/mdlib/mdebin.c b/src/gromacs/mdlib/mdebin.c index e7811e9374..ce60f69c12 100644 --- a/src/gromacs/mdlib/mdebin.c +++ b/src/gromacs/mdlib/mdebin.c @@ -547,7 +547,7 @@ t_mdebin *init_mdebin(ener_file_t fp_ene, { ni = groups->grps[egcTC].nm_ind[i]; sprintf(buf, "T-%s", *(groups->grpname[ni])); - grpnms[i] = strdup(buf); + grpnms[i] = gmx_strdup(buf); } md->itemp = get_ebin_space(md->ebin, md->nTC, (const char **)grpnms, unit_temp_K); @@ -565,9 +565,9 @@ t_mdebin *init_mdebin(ener_file_t fp_ene, for (j = 0; (j < md->nNHC); j++) { sprintf(buf, "Xi-%d-%s", j, bufi); - grpnms[2*(i*md->nNHC+j)] = strdup(buf); + grpnms[2*(i*md->nNHC+j)] = gmx_strdup(buf); sprintf(buf, "vXi-%d-%s", j, bufi); - grpnms[2*(i*md->nNHC+j)+1] = strdup(buf); + grpnms[2*(i*md->nNHC+j)+1] = gmx_strdup(buf); } } md->itc = get_ebin_space(md->ebin, md->mde_n, @@ -580,9 +580,9 @@ t_mdebin *init_mdebin(ener_file_t fp_ene, for (j = 0; (j < md->nNHC); j++) { sprintf(buf, "Xi-%d-%s", j, bufi); - grpnms[2*(i*md->nNHC+j)] = strdup(buf); + grpnms[2*(i*md->nNHC+j)] = gmx_strdup(buf); sprintf(buf, "vXi-%d-%s", j, bufi); - grpnms[2*(i*md->nNHC+j)+1] = strdup(buf); + grpnms[2*(i*md->nNHC+j)+1] = gmx_strdup(buf); } } md->itcb = get_ebin_space(md->ebin, md->mdeb_n, @@ -596,9 +596,9 @@ t_mdebin *init_mdebin(ener_file_t fp_ene, ni = groups->grps[egcTC].nm_ind[i]; bufi = *(groups->grpname[ni]); sprintf(buf, "Xi-%s", bufi); - grpnms[2*i] = strdup(buf); + grpnms[2*i] = gmx_strdup(buf); sprintf(buf, "vXi-%s", bufi); - grpnms[2*i+1] = strdup(buf); + grpnms[2*i+1] = gmx_strdup(buf); } md->itc = get_ebin_space(md->ebin, md->mde_n, (const char **)grpnms, unit_invtime); @@ -612,7 +612,7 @@ t_mdebin *init_mdebin(ener_file_t fp_ene, { ni = groups->grps[egcTC].nm_ind[i]; sprintf(buf, "Lamb-%s", *(groups->grpname[ni])); - grpnms[i] = strdup(buf); + grpnms[i] = gmx_strdup(buf); } md->itc = get_ebin_space(md->ebin, md->mde_n, (const char **)grpnms, ""); } @@ -628,11 +628,11 @@ t_mdebin *init_mdebin(ener_file_t fp_ene, { ni = groups->grps[egcACC].nm_ind[i]; sprintf(buf, "Ux-%s", *(groups->grpname[ni])); - grpnms[3*i+XX] = strdup(buf); + grpnms[3*i+XX] = gmx_strdup(buf); sprintf(buf, "Uy-%s", *(groups->grpname[ni])); - grpnms[3*i+YY] = strdup(buf); + grpnms[3*i+YY] = gmx_strdup(buf); sprintf(buf, "Uz-%s", *(groups->grpname[ni])); - grpnms[3*i+ZZ] = strdup(buf); + grpnms[3*i+ZZ] = gmx_strdup(buf); } md->iu = get_ebin_space(md->ebin, 3*md->nU, (const char **)grpnms, unit_vel); sfree(grpnms); @@ -846,7 +846,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir, { /* state for the fep_vals, if we have alchemical sampling */ sprintf(buf, "%s", "Thermodynamic state"); - setname[s] = strdup(buf); + setname[s] = gmx_strdup(buf); s += 1; } @@ -862,7 +862,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir, default: sprintf(buf, "%s (%s)", "Total Energy", unit_energy); } - setname[s] = strdup(buf); + setname[s] = gmx_strdup(buf); s += 1; } @@ -888,7 +888,7 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir, sprintf(buf, "%s %s = %.4f", dhdl, efpt_singular_names[i], lam); } - setname[s] = strdup(buf); + setname[s] = gmx_strdup(buf); s += 1; } } @@ -935,14 +935,14 @@ extern FILE *open_dhdl(const char *filename, const t_inputrec *ir, ir->simtempvals->temperatures[s-(nsetsbegin)], unit_temp_K); } - setname[s] = strdup(buf); + setname[s] = gmx_strdup(buf); s++; } if (write_pV) { np = sprintf(buf, "pV (%s)", unit_energy); - setname[nsetsextend-1] = strdup(buf); /* the first entry after - nsets */ + setname[nsetsextend-1] = gmx_strdup(buf); /* the first entry after + nsets */ } xvgr_legend(fp, nsetsextend, (const char **)setname, oenv); @@ -1547,7 +1547,7 @@ void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR, nj = groups->grps[egcENER].nm_ind[j]; sprintf(buf, "%s-%s", *(groups->grpname[ni]), *(groups->grpname[nj])); - md->print_grpnms[n++] = strdup(buf); + md->print_grpnms[n++] = gmx_strdup(buf); } } } diff --git a/src/gromacs/mdlib/qm_gaussian.c b/src/gromacs/mdlib/qm_gaussian.c index 83d9c7c7ad..07aaacca79 100644 --- a/src/gromacs/mdlib/qm_gaussian.c +++ b/src/gromacs/mdlib/qm_gaussian.c @@ -200,7 +200,7 @@ void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm) if (buf) { - qm->gauss_dir = strdup(buf); + qm->gauss_dir = gmx_strdup(buf); } else { @@ -210,7 +210,7 @@ void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm) buf = getenv("GMX_QM_GAUSS_EXE"); if (buf) { - qm->gauss_exe = strdup(buf); + qm->gauss_exe = gmx_strdup(buf); } else { @@ -219,7 +219,7 @@ void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm) buf = getenv("GMX_QM_MODIFIED_LINKS_DIR"); if (buf) { - qm->devel_dir = strdup (buf); + qm->devel_dir = gmx_strdup (buf); } else { diff --git a/src/gromacs/mdlib/tpi.c b/src/gromacs/mdlib/tpi.c index 9452fb3c3e..c19a5ef38c 100644 --- a/src/gromacs/mdlib/tpi.c +++ b/src/gromacs/mdlib/tpi.c @@ -375,25 +375,25 @@ double do_tpi(FILE *fplog, t_commrec *cr, snew(leg, 4+nener); e = 0; sprintf(str, "-kT log(/)"); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); sprintf(str, "f. -kT log"); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); sprintf(str, "f. "); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); sprintf(str, "f. V"); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); sprintf(str, "f. "); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); for (i = 0; i < ngid; i++) { sprintf(str, "f. ", *(groups->grpname[groups->grps[egcENER].nm_ind[i]])); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); } if (bDispCorr) { sprintf(str, "f. "); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); } if (bCharge) { @@ -401,17 +401,17 @@ double do_tpi(FILE *fplog, t_commrec *cr, { sprintf(str, "f. ", *(groups->grpname[groups->grps[egcENER].nm_ind[i]])); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); } if (bRFExcl) { sprintf(str, "f. "); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); } if (EEL_FULL(fr->eeltype)) { sprintf(str, "f. "); - leg[e++] = strdup(str); + leg[e++] = gmx_strdup(str); } } xvgr_legend(fp_tpi, 4+nener, (const char**)leg, oenv); diff --git a/src/gromacs/pulling/pull.c b/src/gromacs/pulling/pull.c index 677c48fa5d..d84d9b1539 100644 --- a/src/gromacs/pulling/pull.c +++ b/src/gromacs/pulling/pull.c @@ -177,7 +177,7 @@ static FILE *open_pull_out(const char *fn, t_pull *pull, const output_env_t oenv if (pull->dim[m]) { sprintf(buf, "%d %s%c", c+1, "c", 'X'+m); - setname[nsets] = strdup(buf); + setname[nsets] = gmx_strdup(buf); nsets++; } } @@ -187,7 +187,7 @@ static FILE *open_pull_out(const char *fn, t_pull *pull, const output_env_t oenv if (pull->dim[m]) { sprintf(buf, "%d %s%c", c+1, "d", 'X'+m); - setname[nsets] = strdup(buf); + setname[nsets] = gmx_strdup(buf); nsets++; } } @@ -195,7 +195,7 @@ static FILE *open_pull_out(const char *fn, t_pull *pull, const output_env_t oenv else { sprintf(buf, "%d", c+1); - setname[nsets] = strdup(buf); + setname[nsets] = gmx_strdup(buf); nsets++; } } diff --git a/src/gromacs/pulling/pull_rotation.c b/src/gromacs/pulling/pull_rotation.c index 11367c6878..ef7a870ed6 100644 --- a/src/gromacs/pulling/pull_rotation.c +++ b/src/gromacs/pulling/pull_rotation.c @@ -941,7 +941,7 @@ static FILE *open_rot_out(const char *fn, t_rot *rot, const output_env_t oenv) add_to_string_aligned(&LegendStr, buf); sprintf(buf2, "%s (degrees)", buf); - setname[nsets] = strdup(buf2); + setname[nsets] = gmx_strdup(buf2); nsets++; } for (g = 0; g < rot->ngrp; g++) @@ -961,19 +961,19 @@ static FILE *open_rot_out(const char *fn, t_rot *rot, const output_env_t oenv) } add_to_string_aligned(&LegendStr, buf); sprintf(buf2, "%s (degrees)", buf); - setname[nsets] = strdup(buf2); + setname[nsets] = gmx_strdup(buf2); nsets++; sprintf(buf, "tau%d", g); add_to_string_aligned(&LegendStr, buf); sprintf(buf2, "%s (kJ/mol)", buf); - setname[nsets] = strdup(buf2); + setname[nsets] = gmx_strdup(buf2); nsets++; sprintf(buf, "energy%d", g); add_to_string_aligned(&LegendStr, buf); sprintf(buf2, "%s (kJ/mol)", buf); - setname[nsets] = strdup(buf2); + setname[nsets] = gmx_strdup(buf2); nsets++; } fprintf(fp, "#\n"); diff --git a/src/gromacs/selection/params.cpp b/src/gromacs/selection/params.cpp index 4ea326b91e..73b190d121 100644 --- a/src/gromacs/selection/params.cpp +++ b/src/gromacs/selection/params.cpp @@ -46,6 +46,7 @@ #include "gromacs/selection/position.h" #include "gromacs/selection/selmethod.h" #include "gromacs/selection/selparam.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" #include "gromacs/utility/messagestringcollector.h" @@ -539,7 +540,7 @@ parse_values_varnum(const SelectionParserValueList &values, param->val.u.r[i++] = value->u.r.r1; break; case STR_VALUE: - param->val.u.s[i++] = strdup(value->stringValue().c_str()); + param->val.u.s[i++] = gmx_strdup(value->stringValue().c_str()); break; case POS_VALUE: copy_rvec(value->u.x, param->val.u.p->x[i++]); break; default: /* Should not be reached */ @@ -864,7 +865,7 @@ parse_values_std(const SelectionParserValueList &values, param->val.u.r[i] = value->u.r.r1; break; case STR_VALUE: - param->val.u.s[i] = strdup(value->stringValue().c_str()); + param->val.u.s[i] = gmx_strdup(value->stringValue().c_str()); break; case POS_VALUE: gmx_ana_pos_init_const(¶m->val.u.p[i], value->u.x); diff --git a/src/gromacs/selection/parsetree.cpp b/src/gromacs/selection/parsetree.cpp index 3ba3e572a9..926aae201d 100644 --- a/src/gromacs/selection/parsetree.cpp +++ b/src/gromacs/selection/parsetree.cpp @@ -228,6 +228,7 @@ #include "gromacs/selection/poscalc.h" #include "gromacs/selection/selection.h" #include "gromacs/selection/selmethod.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/file.h" #include "gromacs/utility/messagestringcollector.h" @@ -579,7 +580,7 @@ _gmx_sel_init_arithmetic(const gmx::SelectionTreeElementPointer &left, buf[0] = op; buf[1] = 0; sel->setName(buf); - sel->u.arith.opstr = strdup(buf); + sel->u.arith.opstr = gmx_strdup(buf); sel->child = left; sel->child->next = right; return sel; @@ -910,7 +911,7 @@ _gmx_sel_init_group_by_name(const char *name, yyscan_t scanner) SelectionTreeElementPointer sel(new SelectionTreeElement(SEL_GROUPREF)); _gmx_selelem_set_vtype(sel, GROUP_VALUE); sel->setName(gmx::formatString("group \"%s\"", name)); - sel->u.gref.name = strdup(name); + sel->u.gref.name = gmx_strdup(name); sel->u.gref.id = -1; if (_gmx_sel_lexer_has_groups_set(scanner)) @@ -1077,7 +1078,7 @@ _gmx_sel_assign_variable(const char *name, sc->symtab->addVariable(name, root->child); } srenew(sc->varstrs, sc->nvars + 1); - sc->varstrs[sc->nvars] = strdup(pselstr); + sc->varstrs[sc->nvars] = gmx_strdup(pselstr); ++sc->nvars; if (_gmx_sel_is_lexer_interactive(scanner)) { diff --git a/src/gromacs/selection/scanner_internal.cpp b/src/gromacs/selection/scanner_internal.cpp index 9fdebc7118..1b5ecb4037 100644 --- a/src/gromacs/selection/scanner_internal.cpp +++ b/src/gromacs/selection/scanner_internal.cpp @@ -102,7 +102,7 @@ init_param_token(YYSTYPE *yylval, gmx_ana_selparam_t *param, bool bBoolNo) } else { - yylval->str = param->name ? strdup(param->name) : NULL; + yylval->str = param->name ? gmx_strdup(param->name) : NULL; } return PARAM; } @@ -336,7 +336,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng, if (symtype == gmx::SelectionParserSymbol::PositionSymbol) { state->bMatchOf = true; - yylval->str = strdup(symbol->name().c_str()); + yylval->str = gmx_strdup(symbol->name().c_str()); state->prev_pos_kw = 2; return KEYWORD_POS; } diff --git a/src/gromacs/selection/tests/toputils.cpp b/src/gromacs/selection/tests/toputils.cpp index 9a2f39e028..ec090acc22 100644 --- a/src/gromacs/selection/tests/toputils.cpp +++ b/src/gromacs/selection/tests/toputils.cpp @@ -173,7 +173,7 @@ void TopologyManager::initAtomTypes(int count, const char *const types[]) atomtypes_.reserve(count); for (int i = 0; i < count; ++i) { - atomtypes_.push_back(strdup(types[i])); + atomtypes_.push_back(gmx_strdup(types[i])); } snew(top_->atoms.atomtype, top_->atoms.nr); for (int i = 0, j = 0; i < top_->atoms.nr; ++i, ++j) diff --git a/src/gromacs/topology/atomprop.cpp b/src/gromacs/topology/atomprop.cpp index 8d593b37ee..926826b5ff 100644 --- a/src/gromacs/topology/atomprop.cpp +++ b/src/gromacs/topology/atomprop.cpp @@ -180,8 +180,8 @@ static void add_prop(aprop_t *ap, gmx_residuetype_t *restype, ap->bAvail[i] = FALSE; } } - ap->atomnm[ap->nprop] = strdup(atomnm); - ap->resnm[ap->nprop] = strdup(resnm); + ap->atomnm[ap->nprop] = gmx_strdup(atomnm); + ap->resnm[ap->nprop] = gmx_strdup(resnm); j = ap->nprop; ap->nprop++; } @@ -252,7 +252,7 @@ static void set_prop(gmx_atomprop_t aps, int eprop) ap = &ap2->prop[eprop]; if (!ap->bSet) { - ap->db = strdup(fns[eprop]); + ap->db = gmx_strdup(fns[eprop]); ap->def = def[eprop]; read_prop(aps, eprop, fac[eprop]); diff --git a/src/gromacs/topology/index.cpp b/src/gromacs/topology/index.cpp index 34201277c9..65f9b2abae 100644 --- a/src/gromacs/topology/index.cpp +++ b/src/gromacs/topology/index.cpp @@ -127,7 +127,7 @@ void add_grp(t_blocka *b, char ***gnames, int nra, atom_id a[], const char *name srenew(b->index, b->nr+2); srenew(*gnames, b->nr+1); - (*gnames)[b->nr] = strdup(name); + (*gnames)[b->nr] = gmx_strdup(name); srenew(b->a, b->nra+nra); for (i = 0; (i < nra); i++) @@ -275,9 +275,9 @@ static void analyse_other(const char ** restype, t_atoms *atoms, if (l == nrestp) { srenew(restp, nrestp+1); - restp[nrestp].rname = strdup(rname); + restp[nrestp].rname = gmx_strdup(rname); restp[nrestp].bNeg = FALSE; - restp[nrestp].gname = strdup(rname); + restp[nrestp].gname = gmx_strdup(rname); nrestp++; } @@ -624,7 +624,7 @@ void analyse(t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool b if (!found) { srenew(p_typename, ntypes+1); - p_typename[ntypes++] = strdup(restype[i]); + p_typename[ntypes++] = gmx_strdup(restype[i]); } } @@ -706,7 +706,7 @@ void analyse(t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool b { srenew(gb->index, gb->nr+2); srenew(*gn, gb->nr+1); - (*gn)[gb->nr] = strdup("Water_and_ions"); + (*gn)[gb->nr] = gmx_strdup("Water_and_ions"); srenew(gb->a, gb->nra+nwater+nion); if (nwater > 0) { @@ -776,7 +776,7 @@ t_blocka *init_index(const char *gfile, char ***grpname) b->index[0] = 0; } b->index[b->nr] = b->index[b->nr-1]; - (*grpname)[b->nr-1] = strdup(str); + (*grpname)[b->nr-1] = gmx_strdup(str); } else { @@ -968,7 +968,7 @@ static void rd_groups(t_blocka *grps, char **grpname, char *gnames[], fprintf(stderr, "There is one group in the index\n"); gnr1 = 0; } - gnames[i] = strdup(grpname[gnr1]); + gnames[i] = gmx_strdup(grpname[gnr1]); isize[i] = grps->index[gnr1+1]-grps->index[gnr1]; snew(index[i], isize[i]); for (j = 0; (j < isize[i]); j++) diff --git a/src/gromacs/topology/symtab.cpp b/src/gromacs/topology/symtab.cpp index 763d6f4f42..98a99e3a9a 100644 --- a/src/gromacs/topology/symtab.cpp +++ b/src/gromacs/topology/symtab.cpp @@ -166,7 +166,7 @@ static char **enter_buf(t_symtab *symtab, char *name) if (symbuf->buf[i] == NULL) { symtab->nr++; - symbuf->buf[i] = strdup(name); + symbuf->buf[i] = gmx_strdup(name); return &(symbuf->buf[i]); } else if (strcmp(symbuf->buf[i], name) == 0) @@ -190,7 +190,7 @@ static char **enter_buf(t_symtab *symtab, char *name) symbuf = symbuf->next; symtab->nr++; - symbuf->buf[0] = strdup(name); + symbuf->buf[0] = gmx_strdup(name); return &(symbuf->buf[0]); } diff --git a/src/programs/view/buttons.cpp b/src/programs/view/buttons.cpp index 21012794ec..a8a39f11e0 100644 --- a/src/programs/view/buttons.cpp +++ b/src/programs/view/buttons.cpp @@ -42,6 +42,7 @@ #include #include "macros.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/smalloc.h" #include "x11.h" @@ -116,7 +117,7 @@ static bool VBCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data) void set_vbtime(t_x11 *x11, t_butbox *vbox, char *text) { sfree(vbox->wd.text); - vbox->wd.text = strdup(text); + vbox->wd.text = gmx_strdup(text); ExposeWin(x11->disp, vbox->wd.self); } diff --git a/src/programs/view/fgrid.cpp b/src/programs/view/fgrid.cpp index 19a7868da9..a4a2f5a7f0 100644 --- a/src/programs/view/fgrid.cpp +++ b/src/programs/view/fgrid.cpp @@ -203,7 +203,7 @@ static t_fsimple *NewFSimple(void) static void AddFItemName(t_fitem *fitem, char *name) { srenew(fitem->name, ++fitem->nname); - fitem->name[fitem->nname-1] = strdup(name); + fitem->name[fitem->nname-1] = gmx_strdup(name); } static t_fgroup *NewFGroup(void) @@ -358,10 +358,10 @@ static t_fitem *ScanFItem(const char *infile, FILE *in, char *buf) ReadQuoteString(infile, in, get); ReadQuoteString(infile, in, def); ReadQuoteString(infile, in, help); - fitem->set = strdup(set); - fitem->get = strdup(get); - fitem->def = strdup(def); - fitem->help = strdup(help); + fitem->set = gmx_strdup(set); + fitem->get = gmx_strdup(get); + fitem->def = gmx_strdup(def); + fitem->help = gmx_strdup(help); return fitem; } @@ -398,7 +398,7 @@ t_fgrid *FGridFromFile(const char *infile) { fgroup = AddFGridFGroup(fgrid); ReadQuoteString(infile, in, buf); - fgroup->name = strdup(buf); + fgroup->name = gmx_strdup(buf); if ((fscanf(in, "%5d%5d%5d%5d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4) { ReadDlgErr(infile, eNOVALS, "group x,y,w,h"); diff --git a/src/programs/view/manager.cpp b/src/programs/view/manager.cpp index 30f7a31a2f..391dadaf91 100644 --- a/src/programs/view/manager.cpp +++ b/src/programs/view/manager.cpp @@ -230,7 +230,7 @@ void set_file(t_x11 *x11, t_manager *man, const char *trajectory, man->natom = read_first_x(man->oenv, &man->status, trajectory, &(man->time), &(man->x), man->box); - man->trajfile = strdup(trajectory); + man->trajfile = gmx_strdup(trajectory); if (man->natom > man->top.atoms.nr) { gmx_fatal(FARGS, "Topology %s (%d atoms) and trajectory %s (%d atoms) " @@ -240,7 +240,7 @@ void set_file(t_x11 *x11, t_manager *man, const char *trajectory, cool_quote(quote, 255, NULL); sprintf(buf, "%s: %s", *man->top.name, quote); - man->title.text = strdup(buf); + man->title.text = gmx_strdup(buf); man->view = init_view(man->box); at = &(man->top.atoms); aps = gmx_atomprop_init(); diff --git a/src/programs/view/x11.cpp b/src/programs/view/x11.cpp index 0dc1a8913c..9050326242 100644 --- a/src/programs/view/x11.cpp +++ b/src/programs/view/x11.cpp @@ -40,6 +40,7 @@ #include #include "typedefs.h" +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/smalloc.h" #include "Xstuff.h" #include "x11.h" @@ -318,7 +319,7 @@ t_x11 *GetX11(int *argc, char *argv[]) bool bVerbose = false; int i; - title = strdup(argv[0]); + title = gmx_strdup(argv[0]); /* First check environment */ fontname = getenv("GMX_FONT"); @@ -355,7 +356,7 @@ t_x11 *GetX11(int *argc, char *argv[]) break; case 't': sfree(title); - title = strdup(argv[++i]); + title = gmx_strdup(argv[++i]); break; case 'v': bVerbose = true; @@ -481,7 +482,7 @@ t_x11 *GetX11(int *argc, char *argv[]) { x11->bg = LIGHTGREY; } - x11->title = strdup(title); + x11->title = gmx_strdup(title); sfree(title); x11->wlist = NULL; x11->GetNamedColor = &GetNamedColor; diff --git a/src/programs/view/xdlg.cpp b/src/programs/view/xdlg.cpp index 0769d67056..c7f21ad9c2 100644 --- a/src/programs/view/xdlg.cpp +++ b/src/programs/view/xdlg.cpp @@ -419,7 +419,7 @@ void HelpNow(t_dlg *dlg, t_dlgitem *dlgitem) if (bCont) { srenew(lines, ++nlines); - lines[nlines-1] = strdup(buf); + lines[nlines-1] = gmx_strdup(buf); } } } @@ -774,7 +774,7 @@ t_dlg *CreateDlg(t_x11 *x11, Window Parent, const char *title, dlg->data = data; if (title) { - dlg->title = strdup(title); + dlg->title = gmx_strdup(title); } else { diff --git a/src/programs/view/xdlgitem.cpp b/src/programs/view/xdlgitem.cpp index 09940872a5..cf21f2c3dc 100644 --- a/src/programs/view/xdlgitem.cpp +++ b/src/programs/view/xdlgitem.cpp @@ -420,7 +420,7 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) case ButtonPress: /* Calculate new position for caret */ et->pos = strlen(et->buf); - bp = strdup(et->buf); + bp = gmx_strdup(et->buf); xp = event->xbutton.x-XTextWidth(x11->font, win->text, strlen(win->text))- XCARET; while ((et->pos > 0) && (XTextWidth(x11->font, bp, strlen(bp)) > xp)) @@ -571,7 +571,7 @@ t_dlgitem *CreateButton(t_x11 *x11, } else { - lab = strdup(szLab); + lab = gmx_strdup(szLab); } InitWin(&(dlgitem->win), x0, y0, w, h, bw, szLab); sfree(lab); @@ -709,7 +709,7 @@ t_dlgitem *CreateStaticText(t_x11 *x11, snew(dlgitem->u.statictext.lines, nlines); for (i = 0; (i < nlines); i++) { - dlgitem->u.statictext.lines[i] = strdup(lines[i]); + dlgitem->u.statictext.lines[i] = gmx_strdup(lines[i]); } dlgitem->WndProc = WndProcST; @@ -755,7 +755,7 @@ t_dlgitem *CreateEditText(t_x11 *x11, return dlgitem; } -#define SC(src) (strlen(src) ? strdup(src) : NULL) +#define SC(src) (strlen(src) ? gmx_strdup(src) : NULL) void SetDlgitemOpts(t_dlgitem *dlgitem, bool bUseMon, char *set, char *get, char *help) diff --git a/src/programs/view/xutil.cpp b/src/programs/view/xutil.cpp index 83ac88fc57..890d2f6acd 100644 --- a/src/programs/view/xutil.cpp +++ b/src/programs/view/xutil.cpp @@ -39,6 +39,7 @@ #include #include #include +#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/smalloc.h" #include "typedefs.h" #include "xutil.h" @@ -165,7 +166,7 @@ void InitWin(t_windata *win, int x0, int y0, int w, int h, int bw, const char *t win->cursor = 0; if (text) { - win->text = strdup(text); + win->text = gmx_strdup(text); } else {