[gmx-developers] uninitialized data

Alexander Herz aherz.kazan at arcor.de
Wed Apr 22 11:26:40 CEST 2009


Hm..the first documentation of calloc I found on the net didn't mention
that it also initializes the data to 0.
Still it seems a weird thing to do if it provokes false positives in
valgrind.

Alex

David van der Spoel schrieb:
> 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.
>
>




More information about the gromacs.org_gmx-developers mailing list