Page 1 of 1

localtime_r assert failure - is this a bug?

Posted: Mon Feb 27, 2023 2:01 pm
by pythagoras
I have the following code :
  1.  struct tm td;
  2.    //time_t timeval = aMission->timestampStarted;
  3.    time_t timeval = aMission->timestampStarted + UTCTimeOffset;
  4.    localtime_r(&timeval, &td);
  5.    char timeStr[60];
  6.    snprintf(timeStr, 59, "%02d/%02d/%04d %2d:%02d", td.tm_mday, td.tm_mon+1, (td.tm_year+1900), td.tm_hour, td.tm_min);
  7.    char mstr[260];
  8.    snprintf(mstr, 199, "<tr><td>%s</td><td>%s</td>", aMission->name, timeStr);
  9.    httpd_resp_sendstr_chunk(req, mstr);
  10.    if (aMission->timestampStopped != 0) {
  11.       //timeval = aMission->timestampStopped;
  12.       timeval = aMission->timestampStopped + UTCTimeOffset;
  13.       localtime_r(&timeval, &td);
  14.       snprintf(timeStr, 59, "%02d/%02d/%04d %2d:%02d", td.tm_mday, td.tm_mon+1, (td.tm_year+1900), td.tm_hour, td.tm_min);
  15.       snprintf(mstr, 199, "<td>%s</td>", timeStr);
  16.    }
sometimes I get an assert failure:
assert failed: xQueueGenericSend queue.c:837 (pxQueue->pcHead != ((void *)0) || pxQueue->u.xSemaphore.xMutexHolder == ((void *)0) || pxQueue->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle())


Backtrace: 0x4008207e:0x3ffdbfd0 0x4008a641:0x3ffdbff0 0x400918ca:0x3ffdc010 0x4008ae99:0x3ffdc130 0x40082fcf:0x3ffdc170 0x400831c1:0x3ffdc1a0 0x40162909:0x3ffdc1d0 0x4015adec:0x3ffdc1f0 0x400dea5b:0x3ffdc210 0x400dec50:0x3ffdc3d0 0x400dec99:0x3ffdc440 0x400e0859:0x3ffdc470 0x40110ccf:0x3ffdc4a0 0x4010eb6d:0x3ffdc4e0 0x4010f4f8:0x3ffdc5a0 0x4010d721:0x3ffdc5c0 0x401703dd:0x3ffdc5f0 0x4010d9f3:0x3ffdc610
0x4008207e: panic_abort at /opt/esp/esp-idf-5.0.1/esp-idf/components/esp_system/panic.c:423

0x4008a641: esp_system_abort at /opt/esp/esp-idf-5.0.1/esp-idf/components/esp_system/esp_system.c:153

0x400918ca: __assert_func at /opt/esp/esp-idf-5.0.1/esp-idf/components/newlib/assert.c:78

0x4008ae99: xQueueGenericSend at /opt/esp/esp-idf-5.0.1/esp-idf/components/freertos/FreeRTOS-Kernel/queue.c:837 (discriminator 8)

0x40082fcf: lock_release_generic at /opt/esp/esp-idf-5.0.1/esp-idf/components/newlib/locks.c:192

0x400831c1: _lock_release at /opt/esp/esp-idf-5.0.1/esp-idf/components/newlib/locks.c:198
(inlined by) __retarget_lock_release at /opt/esp/esp-idf-5.0.1/esp-idf/components/newlib/locks.c:334

0x40162909: __tz_unlock at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/time/tzlock.c:50

0x4015adec: localtime_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/time/lcltime_r.c:123

0x400dea5b: fileserver_missionPrint at /home/mercieca/projects/Abertax/HEDL/Firmware_ABX043/ESP32/trunk/main/fileserver.c:206

0x400dec50: fileserver_printHtmlMissionEntry at /home/mercieca/projects/Abertax/HEDL/Firmware_ABX043/ESP32/trunk/main/fileserver.c:261


Is this a bug in localtimer_r?
Thanks