Skip to content

Commit ac4896f

Browse files
peffgitster
authored andcommitted
fmt_with_err: add a comment that truncation is OK
Functions like die_errno() use fmt_with_err() to combine the caller-provided format with the strerror() string. We use a fixed stack buffer because we're already handling an error and don't have any way to report another one. Our buffer should generally be big enough to fit this, but if it's not, truncation is our best option. Let's add a comment to that effect, so that anybody auditing the code for truncation bugs knows that this is fine. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bf4baf1 commit ac4896f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

usage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static const char *fmt_with_err(char *buf, int n, const char *fmt)
148148
}
149149
}
150150
str_error[j] = 0;
151+
/* Truncation is acceptable here */
151152
snprintf(buf, n, "%s: %s", fmt, str_error);
152153
return buf;
153154
}

0 commit comments

Comments
 (0)