void loop() {
char local_string[] = "Will this string survive until second call to print_buffer()?";
print_buffer();
buffer[1] = local_string;
}
Since the string is not declared const, it looks to me like the compiler is making a copy of it:
void loop() {
ea: df 93 push r29
ec: cf 93 push r28
ee: cd b7 in r28, 0x3d ; 61 <----- stack pointer
f0: de b7 in r29, 0x3e ; 62 <----- ditto
f2: ee 97 sbiw r28, 0x3e ; 62 <------ 62 is length of the string
f4: 0f b6 in r0, 0x3f ; 63
f6: f8 94 cli
f8: de bf out 0x3e, r29 ; 62 <------ adjusted stack pointer
fa: 0f be out 0x3f, r0 ; 63
fc: cd bf out 0x3d, r28 ; 61
char local_string[] = "Will this string survive until second call to print_buffer()?";
fe: de 01 movw r26, r28
100: 11 96 adiw r26, 0x01 ; 1
102: e0 e0 ldi r30, 0x00 ; 0
104: f1 e0 ldi r31, 0x01 ; 1
106: 8e e3 ldi r24, 0x3E ; 62 <----- copy 62 bytes
108: 01 90 ld r0, Z+
10a: 0d 92 st X+, r0
10c: 81 50 subi r24, 0x01 ; 1
10e: e1 f7 brne .-8 ; 0x108 <loop+0x1e>
print_buffer();
110: 0e 94 5f 00 call 0xbe ; 0xbe <_Z12print_bufferv>
Thus we have a pointer to a copy of the string, on the stack, which does not survive the scope of the loop function. Thus it isn't safe.