September 2019 Update

New! We're moving to the new forum!

ALL new Blog posts will be on the forum.

Please join us there.

This Blog will no longer be updated...

Wednesday, August 21, 2019

Restless night...

Posted: 4:25am

I can't seem to stay focused tonight...

I'm going through the code trying to figure out why it has problems with MySql, but only in two places... So as I'm following through some code, I get to the section that does the compare of CRC values in the payloads to see if it is a valid payload. 

Here's the code I found....

I marked the problem in red...   If you aren't a programmer, don't worry, you will still understand this...  bool means that this "method" or "function" will return a true or false. The method is called payloadCRC32IsOk, so you can figure out what it does just from the name.  This isn't really the problem, but if you want the method to return a value, you have to do so, with a RETURN statement, like RETURN true;

I modified the code, like so....

In green, we can see the GOOD things I did.  

  1. I created a boolean (true/false) variable called retVal.
  2. When the CRC does not match, I set retVal to false
  3. At the end of the method, I return the value of retVal, which could be either true or false

In Red, the mistakes, which I blame on cut and paste!

  1. Redefining the variables by placing a type (bool) in front means it is a different retVal than the one created at the beginning of the method, so whatever I set it to, this is not the variable that is returned from the method at the end.
  2. Same issue for when they do match, whatever this is set to will not be returned from the method.
  3. Also note, it would have returned false because I cut and paste and did not change it.

So I made those changes above NOT realizing the mistakes I made, and ran the code...  Disaster! Everything was saying Failed CRC Check...

Suddenly my heart sank... () I started thinking this whole rewrite was falling apart, and based on a false sense of security. I'm guessing that without any return value specified, it was returning TRUE since I never saw failed crc checks.  When I "fixed" it, and they were ALL failing, I just assumed that it was working properly now, and everything I had was wrong....

When I realized my mistakes, having now spent a couple hours fiddling with this, I finally fixed it, and here's how it is supposed to look...

No more failed CRC checks :)

No comments:

Post a Comment

Any comments deemed off topic or offensive will be removed