shining-man / bsc_fw

Firmware battery safety controller (BSC)
MIT License
98 stars 19 forks source link

Assignment instead of comparison in if statement #67

Closed meikjaeckle closed 8 months ago

meikjaeckle commented 8 months ago

In the following if statement, assignment was used instead of comparison: https://github.com/shining-man/bsc_fw/blob/8075238d0f13a4ee5efc9743936257e9ce5bd892/src/BscSerial.cpp#L426

I would suggest to replace the whole "else" block by following code, to fix the issue and get rid of the additional memory allocation for the String.

Modern variant:

    else
    {
      auto GetReasonStr = [u8_lReason]()
      {
        return (1==u8_lReason) ? "Checksum wrong" : "Filter";
      };

      BSC_LOGE(TAG,"ERROR: device=%i, reason=%s",i,GetReasonStr());
    }

or classic variant:

    else
    {
      const char* reasonStr = (1==u8_lReason)  ? "Checksum wrong" : "Filter";
      BSC_LOGE(TAG,"ERROR: device=%i, reason=%s",i,reasonStr);
    }
shining-man commented 8 months ago

The issue is fixed