Elektrine lite

← Feed

@drj@typo.social

2026-11-09 16:03 UTC

So, using a buffer as both a source and a destination in sprintf() doesn't seem to be explicitly non-compliant. Like this: /* write something into buf */ sprintf(buf, "hello"); /* now use buf as a source string, and a destination. */ sprintf(buf, "(%s)", buf); And yet, i don't think it would be reasonable of me, given the rest of C, to expect this to work. #C

Replies (1)

  • @rk@mastodon.well.com 2026-11-09 16:13

    @drj@typo.social You just activated my trap card! C99’s definition of sprintf says “If copying takes place between objects that overlap, the behavior is undefined.” Why yes I am fun at parties.

    Open ##5510024