https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83448
--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> --- (In reply to David Malcolm from comment #6) > Martin: what is the above code attempting to do? It's not clear to me > (though this may be -ENOCOFFEE on my part, sorry). The purpose of the set_caret_index call is to do just what the comment says: point the caret at the first character in the format string that doesn't fit in the destination. But the only test that exercises the caret location, builtin-sprintf-warn-4.c, doesn't hit that call and the only tests that I have been able to construct where this particular call makes a difference show that it only causes trouble. E.g., this: char d[4]; void f (int i) { if (i < 0 || 3 < i) i = 0; __builtin_sprintf (d, "%*s1234", i, ""); } results in this with the set_caret call: a.c: In function ‘f’: a.c:8:3: warning: ‘1234’ directive writing 4 bytes into a region of size between 1 and 4 [-Wformat-overflow=] __builtin_sprintf (d, "%*s1234", i, ""); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while in this without it: a.c: In function ‘f’: a.c:8:29: warning: ‘1234’ directive writing 4 bytes into a region of size between 1 and 4 [-Wformat-overflow=] __builtin_sprintf (d, "%*s1234", i, ""); ^~~~ a.c:8:3: note: ‘__builtin_sprintf’ output between 5 and 8 bytes into a destination of size 4 __builtin_sprintf (d, "%*s1234", i, ""); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ So it looks like it can be removed.