arcao / Syslog

An Arduino library for logging to Syslog server in IETF format (RFC 5424) and BSD format (RFC 3164)
MIT License
119 stars 48 forks source link

logf_P fails #18

Open dragondaud opened 6 years ago

dragondaud commented 6 years ago

Exception 3: LoadStoreError: Processor internal physical address or data error during load or store 0x4021ec20: vsnprintf at /Users/igrokhotkov/e/newlib-xtensa/xtensa-lx106-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vsnprintf.c line 42 0x401004e4: malloc at C:\Users\daud\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1672 0x4021abc4: operator new[](unsigned int) at C:\Users\daud\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266/abi.cpp line 71 0x4021751a: Syslog::vlogf(unsigned short, char const, __va_list_tag) at C:\Users\daud\Documents\Arduino\libraries\Syslog\src/Syslog.cpp line 38 0x40217568: Syslog::logf(char const, ...) at C:\Users\daud\Documents\Arduino\libraries\Syslog\src/Syslog.cpp line 38 0x4020d6e3: setup at C:\Users\daud\Documents\Arduino\myClock/myClock.ino line 116

This works as expected: Serial.printf_P(PSTR("setup: %s, %s, %s, %d, %d \r\n"), location.c_str(), timezone.c_str(), milTime ? "true" : "false", brightness, light);

This does not: syslog.logf_P(PSTR("setup: %s|%s|%s|%d|%d"), location.c_str(), timezone.c_str(), milTime ? "true" : "false", brightness, light);

My full code is available at https://github.com/dragondaud/myClock

yunjova commented 4 years ago

The function "bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args)" in file Syslog.cpp has a bug which (probably) is the reason for this failure.

Solution: Replace "vsnprintf(message, len + 1, fmt_P, args);" inside the if statement with "vsnprintf**### _P**(message, len + 1, fmt_P, args);". (Add "_P" to call the correct function.)

Kind regards