Take this minimal exa ple:
static const char FWVER[] PROGMEM = {"The quick brown fox jumped over the lazy dog."};
char copy[48];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(500);
memset(copy, '\0', 48);
strncpy_P(copy, FWVER, strlen(FWVER));
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(copy);
delay(1000);
}
When I compile for an AVR board such as the UNO there is no problem. However when I compile for the Pico RP2040, I get:
In file included from /home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/api/../../../ArduinoCore-API/api/String.h:33,
from /home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/api/String.h:2,
from /home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/api/../../../ArduinoCore-API/api/IPAddress.h:23,
from /home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/api/../../../ArduinoCore-API/api/ArduinoAPI.h:30,
from /home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/api/ArduinoAPI.h:2,
from /home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/Arduino.h:28,
from /home/johnc/.cache/arduino/sketches/4E1F0460278FE026E8F8598D1F5C9E18/sketch/sketch_jul3a.ino.cpp:1:
/tmp/.arduinoIDE-unsaved202563-13553-1ewk6mf.hvc3/sketch_jul3a/sketch_jul3a.ino: In function 'void setup()':
/home/johnc/.arduino15/packages/rp2040/hardware/rp2040/4.6.0/cores/rp2040/api/../../../ArduinoCore-API/api/deprecated-avr-comp/avr/pgmspace.h:76:37: warning: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying 45 bytes from a string of the same length [-Wstringop-truncation]
76 | #define strncpy_P(s1, s2, n) strncpy((s1), (s2), (n))
| ~~~~~~~^~~~~~~~~~~~~~~~~
/tmp/.arduinoIDE-unsaved202563-13553-1ewk6mf.hvc3/sketch_jul3a/sketch_jul3a.ino:7:3: note: in expansion of macro 'strncpy_P'
7 | strncpy_P(copy, FWVER, strlen(FWVER));
| ^~~~~~~~~
Sketch uses 57832 bytes (2%) of program storage space. Maximum is 2093056 bytes.
Global variables use 9468 bytes (3%) of dynamic memory, leaving 252676 bytes for local variables. Maximum is 262144 bytes.
Its only a "note" but I am trying to understand why its warning about a truncation? Any why on the Pico but not on AVR boards? The entire line does actually get printed.
Additional question: looking at that macro, do I even need to use strncpy_P on the Pico? I am sure that when I omitted the _P on AVR boards that did result in gobledegook, but the Pico does print the line correctly.
I am using the Earle Pillhower board package, currently at version 4.6.0.