String boundary check (actually char sts[12] )

Sorry if this is a stupid question, i am a beginner in C

The last week i was hunting a weird error, which turned out to be caused by a
char sts[12];
which was over-filled by
sprintf (sts, “@m %0lu: %0d, @h %0lu: %0d (%0d), n %0d”, a, b, c, d, e, f);

Is there no boundary check in the C compiler that would complain?

I mean, it is solv-/avoidable, but one has to first get there.

Just curious.

This would truncate instead of overflow the buffer. You should always use snprintf instead of sprintf for that reason.

snprintf (sts, sizeof(sts), "@m %0lu: %0d, @h %0lu: %0d (%0d), n %0d", a, b, c, d, e, f);

oh, thanks :smile: