Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PID::PID() constructor dereferences uninitialized "myOutput" pointer #4

Closed
Voltara opened this issue Sep 19, 2012 · 0 comments
Closed

Comments

@Voltara
Copy link

Voltara commented Sep 19, 2012

The PID::PID() constructor prematurely accesses uninitialized members, which can potentially dereference an uninitialized pointer (this causes a Segmentation Fault when testing locally on my Linux box.)

  PID::PID(double* Input, double* Output, double* Setpoint,
          double Kp, double Ki, double Kd, int ControllerDirection)
  {
          PID::SetOutputLimits(0, 255);                           //default output limit corresponds to 

The SetOutputLimits() method depends on members "inAuto" "myOutput" and "ITerm", which have not yet been initialized by the time it is called by the constructor. If "inAuto" (uninitialized) happens to be true, SetOutputLimits() will read+write to a random memory location via the uninitialized pointer "myOutput".

The call to PID::SetControllerDirection() also prematurely accesses uninitialized members, but that appears to be harmless.

br3ttb added a commit that referenced this issue Oct 5, 2012
-Changed Compute() to a bool from a void,  allowing the calling function
to know when the pid calculation has just been evaluated

-cleaned up the initialization code in the constructor
@br3ttb br3ttb closed this as completed Oct 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants