Skip to content

Compiler warning generated when using runge_kutta.c #107

@yantosca

Description

@yantosca

This is a minor issue but I just thought I'd bring it up. When compiling KPP 3.1.1 with gcc 10.2.0, I get this warning:

C_rk_Integrator.c: In function ‘RK_Integrator’:
C_rk_Integrator.c:1045:34: warning: ‘ErrOld’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1045 |        FacGus = FacSafe*(H/Hacc)*pow(Err*Err/ErrOld,(double)(-0.25));
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C_rk_Integrator.c:1045:27: warning: ‘Hacc’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1045 |        FacGus = FacSafe*(H/Hacc)*pow(Err*Err/ErrOld,(double)(-0.25));
      |                         ~~^~~~~~

Which I've traced to this section of code:

 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 /*~~~> Accept/reject step */
 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
      // accept:
      if (Err < ONE) { /*~~~> STEP IS ACCEPTED */
      	FirstStep = 0;
      	ISTATUS[Nacc]++;
      	if (Gustafsson == 1) {
	   /*~~~> Predictive controller of Gustafsson */
	   if (ISTATUS[Nacc] > 1) {
	      FacGus = FacSafe*(H/Hacc)*pow(Err*Err/ErrOld,(KPP_REAL)(-0.25));
	      FacGus = MIN(FacMax,MAX(FacMin,FacGus));
	      Fac = MIN(Fac,FacGus);	
	      Hnew = Fac*H;
	   } /* end if */
	   Hacc = H;
	   ErrOld = MAX((KPP_REAL)1.0e-02,Err);
      	} /* end if */

The compiler is flagging that ErrOld may be uninitialized. It doesn't look like it's used until after the first timestep.

Would it be safe to set e.g. ErrOld = Err just after the FirstStep=0 line? That would remove the warning.

Also a similar situation is in the F90 code but we don't get a warning for that.

This isn't an essential fix but would be more of a cleanup so that we wouldn't generate warnings when building the mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingintegratorsRelated to numerical integrators

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions