# HG changeset patch # User William Astle # Date 1589171904 21600 # Node ID 10f62dc61a75b73f160c1823af1266077064122f # Parent dd9c5cef2e8032c13b5d45a8468981e3da5b7cb5 Fix bad usage of sprintf() Usage of sprintf() to append to a string in the form of sprintf(buf, "%s...", buf...) is undefined, regardless whether it worked on a lot of older systems. It was always a bad idea and it now breaks on current glibc and gcc development environments. The moral: if any of your code uses sprintf() in a way similar to the above, fix it. It may not fail in a benign way. diff -r dd9c5cef2e80 -r 10f62dc61a75 lwasm/list.c --- a/lwasm/list.c Thu Feb 06 15:04:05 2020 -0700 +++ b/lwasm/list.c Sun May 10 22:38:24 2020 -0600 @@ -231,28 +231,25 @@ char s[64] = ""; if (CURPRAGMA(cl, PRAGMA_C) || CURPRAGMA(cl, PRAGMA_CD)) { + char sch = '(', ech = ')'; + if (CURPRAGMA(cl, PRAGMA_6809)) + { + sch = '['; + ech = ']'; + } if (cl->cycle_base != 0) { - char ch = '('; - if (CURPRAGMA(cl, PRAGMA_6809)) ch = '['; + int est = cl -> cycle_flags & CYCLE_ESTIMATED; if (CURPRAGMA(cl, PRAGMA_CD) && cl->cycle_flags & CYCLE_ADJ) { - sprintf(s, "%c%d+%d", ch, cl->cycle_base, cl->cycle_adj); /* detailed cycle count */ + sprintf(s, "%c%d+%d%s%c", sch, cl->cycle_base, cl->cycle_adj, est ? "+?" : "", ech); /* detailed cycle count */ } else { - sprintf(s, "%c%d", ch, cl->cycle_base + cl->cycle_adj); /* normal cycle count*/ + sprintf(s, "%c%d%s%c", sch, cl->cycle_base + cl->cycle_adj, est ? "+?" : "", ech); /* normal cycle count*/ } - - if (cl->cycle_flags & CYCLE_ESTIMATED) - strcat(s, "+?"); - as->cycle_total += cl->cycle_base + cl->cycle_adj; - - ch = ')'; - if (CURPRAGMA(cl, PRAGMA_6809)) ch = ']'; - sprintf(s, "%s%c", s, ch); } }