comparison lwasm/list.c @ 508:10f62dc61a75

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.
author William Astle <lost@l-w.ca>
date Sun, 10 May 2020 22:38:24 -0600
parents 40c32a0af8c8
children f3018ed5e30e
comparison
equal deleted inserted replaced
507:dd9c5cef2e80 508:10f62dc61a75
229 229
230 /* display cycle counts */ 230 /* display cycle counts */
231 char s[64] = ""; 231 char s[64] = "";
232 if (CURPRAGMA(cl, PRAGMA_C) || CURPRAGMA(cl, PRAGMA_CD)) 232 if (CURPRAGMA(cl, PRAGMA_C) || CURPRAGMA(cl, PRAGMA_CD))
233 { 233 {
234 char sch = '(', ech = ')';
235 if (CURPRAGMA(cl, PRAGMA_6809))
236 {
237 sch = '[';
238 ech = ']';
239 }
234 if (cl->cycle_base != 0) 240 if (cl->cycle_base != 0)
235 { 241 {
236 char ch = '('; 242 int est = cl -> cycle_flags & CYCLE_ESTIMATED;
237 if (CURPRAGMA(cl, PRAGMA_6809)) ch = '[';
238 243
239 if (CURPRAGMA(cl, PRAGMA_CD) && cl->cycle_flags & CYCLE_ADJ) 244 if (CURPRAGMA(cl, PRAGMA_CD) && cl->cycle_flags & CYCLE_ADJ)
240 { 245 {
241 sprintf(s, "%c%d+%d", ch, cl->cycle_base, cl->cycle_adj); /* detailed cycle count */ 246 sprintf(s, "%c%d+%d%s%c", sch, cl->cycle_base, cl->cycle_adj, est ? "+?" : "", ech); /* detailed cycle count */
242 } 247 }
243 else 248 else
244 { 249 {
245 sprintf(s, "%c%d", ch, cl->cycle_base + cl->cycle_adj); /* normal cycle count*/ 250 sprintf(s, "%c%d%s%c", sch, cl->cycle_base + cl->cycle_adj, est ? "+?" : "", ech); /* normal cycle count*/
246 } 251 }
247
248 if (cl->cycle_flags & CYCLE_ESTIMATED)
249 strcat(s, "+?");
250
251 as->cycle_total += cl->cycle_base + cl->cycle_adj; 252 as->cycle_total += cl->cycle_base + cl->cycle_adj;
252
253 ch = ')';
254 if (CURPRAGMA(cl, PRAGMA_6809)) ch = ']';
255 sprintf(s, "%s%c", s, ch);
256 } 253 }
257 } 254 }
258 255
259 if (of) fprintf(of, "%-8s", s); 256 if (of) fprintf(of, "%-8s", s);
260 257