STMicroelectronics / iis3dwb-pid

iis3dwb platform independent driver based on Standard C language and compliant with MISRA standard
BSD 3-Clause "New" or "Revised" License
12 stars 9 forks source link

Cppcheck issues #10

Closed escherstair closed 1 year ago

escherstair commented 1 year ago

I used cppcheck tool to do a static analysis of the source code, and I get some potential issues. As an example, in the following snippet of code https://github.com/STMicroelectronics/iis3dwb-pid/blob/b85e3d23bbc5806011dd202a528308099cb24204/iis3dwb_reg.c#L438-L449 if the first iis3dwb_read_reg() fails (and returns ret != 0), the second iis3dwb_read_reg() is not executed, and so the switch() accesses to ctrl6_c.xl_axis_sel uninitialized. I suggest to change this snippet into

  *val = IIS3DWB_ENABLE_ALL;  /* so that it's always set to "the default" */

  ret = iis3dwb_read_reg(ctx, IIS3DWB_CTRL4_C, (uint8_t *)&ctrl4_c, 1);
  if (ret != 0) { return ret; }

  ret = iis3dwb_read_reg(ctx, IIS3DWB_CTRL6_C, (uint8_t *)&ctrl6_c, 1);
  if (ret != 0) { return ret; }

  switch ((ctrl4_c._1ax_to_3regout << 4) + ctrl6_c.xl_axis_sel)

Cppcheck gives a list of potential issues in the files and I suggest to fix all of them. @avisconti if you agree I can make a PR. Let me know

avisconti commented 1 year ago

Cppcheck gives a list of potential issues in the files and I suggest to fix all of them. @avisconti if you agree I can make a PR. Let me know

Yes, pls. If you can prepare a PR like this I will review it! Thanks for your help.

escherstair commented 1 year ago

I decided to fix in a different way. @avisconti can you have a look to the PR, please?

escherstair commented 1 year ago

Fixed with commit https://github.com/STMicroelectronics/iis3dwb-pid/commit/95b1900af75fd7e63c37e50e72a336528ae619b4