Skip to content

Commit d290472

Browse files
committed
altos: Deal with 8-character version numbers
With 8 characters, the version number isn't null-terminated, so we need to limit use to the available length in a couple of places. Signed-off-by: Keith Packard <[email protected]>
1 parent 76358fb commit d290472

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/kernel/ao_cmd.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ ao_reboot(void)
270270
#endif
271271

272272
#if HAS_VERSION
273+
#define _stringify(x) #x
274+
#define stringify(x) _stringify(x)
273275
static void
274276
version(void)
275277
{
@@ -307,7 +309,7 @@ version(void)
307309
, (unsigned) ((uint32_t) AO_BOOT_APPLICATION_BOUND - (uint32_t) AO_BOOT_APPLICATION_BASE)
308310
#endif
309311
);
310-
printf("software-version %s\n", ao_version);
312+
printf("software-version %." stringify(AO_MAX_VERSION) "s\n", ao_version);
311313
}
312314
#endif
313315

src/product/ao_flash_task.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ ao_panic(uint8_t reason)
2929
for (;;);
3030
}
3131

32-
void
33-
ao_put_string(const char *s)
32+
static void
33+
ao_put_stringn(const char *s, int max)
3434
{
3535
char c;
36-
while ((c = *s++)) {
36+
while (max--) {
37+
c = *s++;
38+
if (!c)
39+
break;
3740
if (c == '\n')
3841
ao_usb_putchar('\r');
3942
ao_usb_putchar(c);
4043
}
4144
}
4245

46+
void
47+
ao_put_string(const char *s)
48+
{
49+
ao_put_stringn(s, 65535);
50+
}
51+
4352
static void
4453
ao_application(void)
4554
{
@@ -149,7 +158,7 @@ ao_show_version(void)
149158
ao_put_hex((uint32_t) AO_BOOT_APPLICATION_BASE);
150159
ao_usb_putchar(' ');
151160
ao_put_hex((uint32_t) AO_BOOT_APPLICATION_BOUND);
152-
ao_put_string("\nsoftware-version "); ao_put_string(ao_version);
161+
ao_put_string("\nsoftware-version "); ao_put_stringn(ao_version, AO_MAX_VERSION);
153162
ao_put_string("\n");
154163
}
155164

0 commit comments

Comments
 (0)