Potential crashing bug in dsi_init in the H7 Video library

Hi,

I've been debugging some instability in my app for a few days and I've discovered the cause. It's this function: ArduinoCore-mbed/libraries/Arduino_H7_Video/src/dsi.cpp at 06d7756fc51651a20df0e1b6095cabf6f4a0c8c4 · arduino/ArduinoCore-mbed · GitHub

This function is declared to return an int but it returns nothing.

This bug is obvious when the code is compiled with warnings enabled. It's undefined behaviour and it can cause stack corruption. Running with the sanitizer enabled also catches it.

I will fix this but it points to something we need to pay attention to. In a world, where we want our tools to help us build stable projects or where
network connected IoT systems are increasingly in danger of cyberattack, having an Arduino core which cannot compile with -Wall -Wextra -Werror -Wno-vla and run with -fsanitizer=undefined (and trap mode enabled) has a number of knock on effects for the community:

  1. It means upgrading compilers causes crashes and without upgrading compilers we can’t use the tools being developed to spot defects in production. Example: the latest address sanitizer could run bare metal on a Giga. Sadly, we cannot use a really modern compiler with the Display Shield so we want use the address sanitizer API without effort. We can’t use the latest optimiser or the latest warnings that detect potential defects.
  2. It means we don't detect bugs that can create subtle instabilities so our projects are less stable.
  3. It creates opportunities for security defects.

I encourage everyone involved to keep this in the back of their minds.

All developers are human. Defects in code is the natural state of software. We need to be as paranoid as possible and we should be able to use modern tools to help us.

In order to make all relevant information available to any who are interested in this subject, I'll share a link to the formal bug report @schnoberts submitted to the Arduino developers:

These are all completely valid statements, but I think that most of the people who will read your post here on the Arduino Forum will not feel the statements to be relevant to them personally, since they don't have any involvement in development of Arduino cores, don't have the capability to add arbitrary flags to their compilation commands, aren't interested in upgrading the compiler, and don't write any code that is security critical.

However, there is something that anyone who is beyond the beginner stage should do to more efficiently write higher quality code: that is to enable compiler warnings in the Arduino IDE preferences, pay attention to any warnings that are printed when compiling, and fix anything in their code that produces warnings. From experience, it seems that many experienced developers who publish code for use by the Arduino community either don't have warnings enabled, or else ignore them.

I'll provide instructions for enabling compiler warnings in the Arduino IDE preferences:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Select "All" from the "Compiler warnings" menu in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.

Some may not feel them relevant personally but I am sure they all want stable working projects and these practices I suggest (and you have provided the info to help with - thank you ) are important. Those of us who aren’t beginner developers and contribute to libraries and the cores others use will no doubt feel this is relevant. It never hurts to be reminded what basic code hygiene looks like :slight_smile:

I know everyone working on the Zephyr core will no doubt be busy and under a deadline but hopefully it will be warning free so we can leverage modern tools and see our code warnings without being overwhelmed by warnings from the core.