21 lines
994 B
C
21 lines
994 B
C
// gnoFmt.c — snprintf format checks (stack %s was the bug).
|
|
// m0 = "%s" of stack str -> 0x4241 ("AB")
|
|
// m1 = "%s" of literal -> 0x5857 ("WX")
|
|
// m2 = "%ld" of 42L -> 0x3234 ("42") (original slot-alias case)
|
|
// m3 = "%d" of 1234 -> 0x3231 ("12")
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
static uint16_t two(const char *s) { return (uint16_t)((uint8_t)s[0] | ((uint8_t)s[1] << 8)); }
|
|
int main(int argc, char **argv) {
|
|
char s[8]; s[0]='A'; s[1]='B'; s[2]='C'; s[3]='D'; s[4]=0;
|
|
char o0[16]; snprintf(o0, sizeof o0, "%s", s);
|
|
char o1[16]; snprintf(o1, sizeof o1, "%s", "WXYZ");
|
|
char o2[16]; snprintf(o2, sizeof o2, "%ld", 42L);
|
|
char o3[16]; snprintf(o3, sizeof o3, "%d", 1234);
|
|
*(volatile uint16_t *)0x025000UL = two(o0);
|
|
*(volatile uint16_t *)0x025002UL = two(o1);
|
|
*(volatile uint16_t *)0x025004UL = two(o2);
|
|
*(volatile uint16_t *)0x025006UL = two(o3);
|
|
for (volatile unsigned long i = 0; i < 300000UL; i++) {}
|
|
return 0;
|
|
}
|