user54202: Probably I'm doing something wrong.
I'm writing an Arduino sketch for ESP32.
Among the others I have this function:
#define HDR_MAX_LENGHT 4
#define CMD_MAX_LENGHT 5
#define ARG_MAX_LENGHT 5
#define ARG_MAX_NUMBER 8

void ProcessLine(HardwareSerial *serial, char *line)
{
  int ret;
  int argc;
  char header[HDR_MAX_LENGHT + 1];
  char cmd[CMD_MAX_LENGHT + 1];
  char argv[ARG_MAX_NUMBER][ARG_MAX_LENGHT + 1];

  return; // for debugging
}

Usage example:
void loop() 
{
    static char inBuf[64];

    if (Serial.available())
    {
      size_t size = Serial.readBytes(inBuf, 64);
      inBuf[size] = '\0';
      ProcessLine(&Serial, inBuf);
    }  
}

In the last days all worked fine.
After adding other code, I noticed that sometimes my program "hangs": nothing runs. Perhaps it goes in an exception trap.
Commenting out the different sections of the code, I discovered that if I remove the declarations of the variables in ProcessLine() no more hangs happen.
The current RAM consumption is negligible: 0.5%.
During the tests NO serial data was received! So the function ProcessLine() was never called.
Hence, only the declaration of the variables lead to the "hang".
I wonder if there are some mistakes in the code above.
Otherwise, how I can further debug my code to understand what I've done wrong?

user7508: As I said in a comment, there is nothing wrong with these declarations.
Now, here are some debugging strategies you may try:

You can rebuild your program with all compiler warnings enabled. Look
carefully at the compiler messages and investigate any warning you
see.

You can continue with your current strategy: put back those
declarations, then try to remove something else. You may find that
there are multiple pieces of code that, when removed, make your
program work again. Chances are the problem resides in one of those
pieces. But then, it may be that the problem is in the interaction
between multiple pieces rather than in one specific piece.

You may just read the code carefully and see if you spot something
suspicious. This can work sometimes: see how @Juraj spotted a buffer
overflow in your code snippet just by reading it.

You can add debug messages across your program, to check what
branches are executed, the values of variables...

I don't know the ESP32 dev environment, but you can check whether the
compiler supports adding “sanitizers”. These are pieces of code added
by the compiler that do run-time checks on your program, and report
problems as they happen. You may want to enable at least an address
sanitizer and an undefined behavior sanitizer.

If the environment supports it, you can try to run the program in a
debugger. No success guaranteed: if the program corrupts its memory,
it may crash in some place unrelated to the actual problem. The
debugger will tell you where it crashed, which may not be very
helpful in this case.

If the ESP dev environment supports neither 5 nor 6, you may try to
run your program on your PC. There are a couple of Arduino-compatible
cores that you can download for running on a PC.



54202: <p>Probably I'm doing something wrong.
I'm writing an Arduino sketch for ESP32.
Among the others I have this function:</p>
<pre><code>#define HDR_MAX_LENGHT 4
#define CMD_MAX_LENGHT 5
#define ARG_MAX_LENGHT 5
#define ARG_MAX_NUMBER 8

void ProcessLine(HardwareSerial *serial, char *line)
{
  int ret;
  int argc;
  char header[HDR_MAX_LENGHT + 1];
  char cmd[CMD_MAX_LENGHT + 1];
  char argv[ARG_MAX_NUMBER][ARG_MAX_LENGHT + 1];

  return; // for debugging
}
</code></pre>
<p>Usage example:</p>
<pre><code>void loop() 
{
    static char inBuf[64];

    if (Serial.available())
    {
      size_t size = Serial.readBytes(inBuf, 64);
      inBuf[size] = '\0';
      ProcessLine(&amp;Serial, inBuf);
    }  
}
</code></pre>
<p>In the last days all worked fine.
After adding other code, I noticed that sometimes my program &quot;hangs&quot;: nothing runs. Perhaps it goes in an exception trap.</p>
<p>Commenting out the different sections of the code, I discovered that if I remove the declarations of the variables in <code>ProcessLine()</code> no more hangs happen.
The current RAM consumption is negligible: 0.5%.</p>
<p>During the tests NO serial data was received! So the function <code>ProcessLine()</code> was <em>never</em> called.
Hence, only the declaration of the variables lead to the &quot;hang&quot;.</p>
<p>I wonder if there are some mistakes in the code above.
Otherwise, how I can further debug my code to understand what I've done wrong?</p>
 7508: <p>As I said in a comment, there is nothing wrong with these declarations.
Now, here are some debugging strategies you may try:</p>
<ol>
<li><p>You can rebuild your program with all compiler warnings enabled. Look
carefully at the compiler messages and investigate any warning you
see.</p>
</li>
<li><p>You can continue with your current strategy: put back those
declarations, then try to remove something else. You may find that
there are multiple pieces of code that, when removed, make your
program work again. Chances are the problem resides in one of those
pieces. But then, it may be that the problem is in the interaction
between multiple pieces rather than in one specific piece.</p>
</li>
<li><p>You may just read the code carefully and see if you spot something
suspicious. This can work sometimes: see how @Juraj spotted a buffer
overflow in your code snippet just by reading it.</p>
</li>
<li><p>You can add debug messages across your program, to check what
branches are executed, the values of variables...</p>
</li>
<li><p>I don't know the ESP32 dev environment, but you can check whether the
compiler supports adding “sanitizers”. These are pieces of code added
by the compiler that do run-time checks on your program, and report
problems as they happen. You may want to enable at least an address
sanitizer and an undefined behavior sanitizer.</p>
</li>
<li><p>If the environment supports it, you can try to run the program in a
debugger. No success guaranteed: if the program corrupts its memory,
it may crash in some place unrelated to the actual problem. The
debugger will tell you where it crashed, which may not be very
helpful in this case.</p>
</li>
<li><p>If the ESP dev environment supports neither 5 nor 6, you may try to
run your program on your PC. There are a couple of Arduino-compatible
cores that you can download for running on a PC.</p>
</li>
</ol>
