Stack smashing protect failure! Found the root cause, but want to understand

Hello friends.

I am using and ESP32 and a Nextion. I want to read text from my nextion. so i created a button to do so.

Here is the code from the callback of my button:

void bt_Alarm1PopCallback(void *ptr)                                                              
{
  
  uint32_t alarmState;
  String str_loweralarm;
  String str_upperalarm;
  bt_Alarm1.getValueDS(&alarmState);
  Serial.println(alarmState);

  if(alarmState!=sonde_pH._alarmState)
  {
    sonde_pH._alarmState=alarmState;
    EEPROM.writeInt(PHVALUEADDR + 4*(sizeof(float)), sonde_pH._alarmState);
    EEPROM.commit();
  }
  
    lowerAlarm.getText(lowerAlarmBuffer,99);
    //sonde_pH._lowerAlarm=lowerAlarmBuffer;
    upperAlarm.getText(upperAlarmBuffer,99);
    //sonde_pH._upperAlarm=upperAlarmBuffer;
}

Sometimes when i push the button, my Nextion restarts and i get this errormessage:

Stack smashing protect failure!

abort() was called at PC 0x400df70c on core 1

Backtrace: 0x4008c6dc:0x3ffb1d20 0x4008c90d:0x3ffb1d40 0x400df70c:0x3ffb1d60 0x400d4637:0x3ffb1d80 0x4011b44d:0x3ffb1dc0 0x400d93da:0x3ffb1de0 0x400d8c66:0x3ffb1e00 0x400d5c33:0x3ffb1e30 0x400dc87d:0x3ffb1fb0 0x40088e19:0x3ffb1fd0

Rebooting...

I figuredout, when i delete String str_loweralarm; String str_upperalarm; from the callback, everything works fine without error.

Anyone an idea why this is so?

thank you

Snippets-r-us

How are lowerAlarmBuffer and upperAlarmBuffer defined?

But it could be anywhere in your code. When you have a buffer overrun error changing the code can often cause the symptoms to go away as you have changed where things are stored in memory. Quite often it is not directly related to the lines you changed. That's why you should not post snippets.

The Nextion display library is absolute S**T! WORST piece of code I've ever seen in a commercial product. Whoever wrote it hasn't got the first clue what he's doing. The code for receiving strings from the display is especially garbage - messages coming from the display are randomly discarded by the library. My advice is ditch the Nextion, and use ANY other display.

Regards,
Ray L.

RayLivingston:
The Nextion display library is absolute S**T! WORST piece of code I've ever seen in a commercial product. Whoever wrote it hasn't got the first clue what he's doing. The code for receiving strings from the display is especially garbage - messages coming from the display are randomly discarded by the library. My advice is ditch the Nextion, and use ANY other display.

Regards,
Ray L.

That's an opinion. Not a solution.
If you feel that strongly about the Nextion library for Arduino, fix it. Here's the source code for it.

If you can show us anything that comes close to the flexibility of the Nextion at a similar price, then I'm sure the world would be beating a path to it.

SteveMann:
That's an opinion. Not a solution.

No, that is a fact, because I HAVE looked at the source code, and verified the many problems therein. I have also talked to several others who have seen EXACTLY the same problems I did. The handling of incoming string messages is absolute C**P! The library WILL, under the right circumstances, simply discard parts of messages, and even entire messages, with no warning. Examination of the code will easily prove that statement. I fixed that problem, enough to complete my last project, but I will never use a Nextion display again.

If you have NOT seen the problem (yet), you should consider yourself very, very lucky.

Regards,
Ray L.

than you fort he answers.

My code is 1000+ lines long and unforutnly i have do deal with the nextion for this project.
And as longer and longer i am working with the nextion lib, i have to admit that its not the best code.

But like i said. my project is so far, that i cant go back. My code is 1000+ long. so its hard to post the whole code and not just snippets

I dont get it, why sometimes the **** eroor appears

Stack smashing protect failure!

abort() was called at PC 0x400df70c on core 1

Backtrace: 0x4008c6dc:0x3ffb1d20 0x4008c90d:0x3ffb1d40 0x400df70c:0x3ffb1d60 0x400d4637:0x3ffb1d80 0x4011b44d:0x3ffb1dc0 0x400d93da:0x3ffb1de0 0x400d8c66:0x3ffb1e00 0x400d5c33:0x3ffb1e30 0x400dc87d:0x3ffb1fb0 0x40088e19:0x3ffb1fd0

Rebooting...

with this code

void bt_Alarm1PopCallback(void *ptr)                                                             
{
 
  uint32_t alarmState;
  String str_loweralarm;
  String str_upperalarm;
  bt_Alarm1.getValueDS(&alarmState);
  Serial.println(alarmState);

  if(alarmState!=sonde_pH._alarmState)
  {
    sonde_pH._alarmState=alarmState;
    EEPROM.writeInt(PHVALUEADDR + 4*(sizeof(float)), sonde_pH._alarmState);
    EEPROM.commit();
  }
 
    lowerAlarm.getText(lowerAlarmBuffer,99);
    //sonde_pH._lowerAlarm=lowerAlarmBuffer;
    upperAlarm.getText(upperAlarmBuffer,99);
    //sonde_pH._upperAlarm=upperAlarmBuffer;
}

lowerAlarmBuffer and upperAlarmBuffer are globaly decalred buffer

char lowerAlarmBuffer[100];
char upperAlarmBuffer[100];

I am desperate. I dont know what the problem is

Thank you

The hate is strong in me=(

WTH is going on. I also get this error with this code: The anoying part is, that the error appears only from time to time.

void bt_Alarm1PopCallback(void *ptr)                                                              
{ 

  uint32_t alarmState;
  bt_Alarm1.getValueDS(&alarmState);
}

Anyone smarter than me has an idea?

Thank you

The most likely reason has already been suggested. The symptom is classic. SOMEWHERE in your code, you're probably writing into memory locations that you don't own causing undefined behavior. Could be from writing beyond the end of an array or some buffer that you've dynamically allocated.

Since you're the only one with the code. You're the only one who can dig through it to find the problem. Even with the code, it's unlikely others would be motivated enough to dig through 1000 lines of someone else's code to find the problem.

Also, it could be that you are overused all available memory.

Manuel_o:
Stack smashing protect failure!

suggests that the heap memory and the stack memory are colliding. I would advice to re-examine your memory usage. Only allocate memory when needed, and deallocate it right after.

Go to GitHub - me-no-dev/EspExceptionDecoder: Exception Stack Trace Decoder for ESP8266 and ESP32, install the ESP32/8266 stack trace decoder.

Copy Backtrace: 0x4008c6dc:0x3ffb1d20 0x4008c90d:0x3ffb1d40 0x400df70c:0x3ffb1d60 0x400d4637:0x3ffb1d80 0x4011b44d:0x3ffb1dc0 0x400d93da:0x3ffb1de0 0x400d8c66:0x3ffb1e00 0x400d5c33:0x3ffb1e30 0x400dc87d:0x3ffb1fb0 0x40088e19:0x3ffb1fd0
into the stack trace decoder. Get a lot more info.

thank you for all the advices sirs.

Hope i will find a solution

Hi Manuel,
I've only just seen this, I agree with Ray about the libraries for the Nextion. You could follow the examples in my tutorial Using Nextion Displays with Arduino, my methods do not use any library. You will have to change your approach to interfacing with the Nextion as my methods are different in the way they work, however, they do work reliably.

1 Like