[gmx-developers] uninitialized data
David van der Spoel
spoel at xray.bmc.uu.se
Tue Apr 21 21:00:00 CEST 2009
Alexander Herz wrote:
> of course it must be
>
> memset(fr,0,sizeof(t_forcerec));
>
> as fr is a pointer
snew does this.
>
> Alex
>
> Alexander Herz schrieb:
>> There appears to be a problem with uninitialized data that might affact
>> the shifted virial and other things:
>>
>> in md.c the following code creates the forcerec:
>>
>> fr = mk_forcerec();
>> init_forcerec(fplog,fr,fcd,inputrec,mtop,cr,box,FALSE,
>> opt2fn("-table",nfile,fnm),opt2fn("-tablep",nfile,fnm),
>> opt2fn("-tableb",nfile,fnm),FALSE,pforce);
>> fr->bSepDVDL = ((Flags & MD_SEPPOT) == MD_SEPPOT);
>>
>>
>> where mk_forcerec() contains:
>>
>> t_forcerec *mk_forcerec(void)
>> {
>> t_forcerec *fr;
>>
>> snew(fr,1);
>>
>> //!!!!!!missing : memset(fr,0,sizeof(fr));
>> return fr;
>> }
>>
>> and init_forcerec() contains:
>> ...
>> if (fr->fshift == NULL)
>> snew(fr->fshift,SHIFTS);
>>
>> if (fr->nbfp == NULL) {
>> fr->ntype = mtop->ffparams.atnr;
>> fr->bBHAM = (mtop->ffparams.functype[0] == F_BHAM);
>> fr->nbfp = mk_nbfp(&mtop->ffparams,fr->bBHAM);
>> }
>> ...
>>
>> Without the missing memset I added as a comment to mk_forcerec,
>> fr->fshift may contain anything
>> and might therefore not be initialized. Valgrind also complains about this.
>>
>> I have not yet had the time to see if this affects the shifted virial
>> problems I reported the other day.
>> I'll look at that tomorrow!
>>
>> Alex
>>
>>
>> _______________________________________________
>> gmx-developers mailing list
>> gmx-developers at gromacs.org
>> http://www.gromacs.org/mailman/listinfo/gmx-developers
>> Please don't post (un)subscribe requests to the list. Use the
>> www interface or send it to gmx-developers-request at gromacs.org.
>>
>
> _______________________________________________
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://www.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-developers-request at gromacs.org.
--
David van der Spoel, Ph.D., Professor of Biology
Molec. Biophys. group, Dept. of Cell & Molec. Biol., Uppsala University.
Box 596, 75124 Uppsala, Sweden. Phone: +46184714205. Fax: +4618511755.
spoel at xray.bmc.uu.se spoel at gromacs.org http://folding.bmc.uu.se
More information about the gromacs.org_gmx-developers
mailing list