#1136959 ccal: Terminal colors broken due to modern compiler sprintf optimization

Package:
ccal
Source:
ccal
Description:
Colorised calendar utility
Submitter:
David Brown
Date:
2026-05-17 16:11:02 UTC
Severity:
normal
#1136959#5
Date:
2026-05-17 16:08:01 UTC
From:
To:
Dear Maintainer,

* What led up to the situation?
  Running ccal on a modern Linux environment with a current compiler toolchain (GCC 14/15).

* What exactly did you do (or not do) that was effective (or ineffective)?
  Executed the `ccal` binary from an ANSI terminal emulator.

* What was the outcome of this action?
  The terminal rendered raw ANSI attribute strings (e.g., "37;42m") as literal text because the escape sequence prefix (`\033[`) was completely dropped from stdout.

  Inspecting `src/cal.c` revealed a classic undefined behavior bug in the `setcolor()` function:
  sprintf(command,"%s3%d;4%dm",command,dos2ansi[attr&0x0F],...);

  Using the destination array variable (`command`) as a source argument (`%s`) inside `sprintf` is undefined behavior under the ISO C standard. Modern aggressive compiler pointer-aliasing optimizations optimize out or strip the initial token entirely.

* What outcome did you expect instead?
  The monthly calendar and special days column should display with correctly rendered terminal background and foreground text colors.

I have attached a minimal patch (`fix-ansi-sprintf.patch`) that eliminates this undefined behavior by bypassing the intermediate `command` buffer entirely, instead streaming the ANSI tokens directly to stdout using standard `fputs` and `fprintf`.