From 7ce4fb948c6d196a376a37840cb80ae95b5897ec Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 Sep 2015 17:08:21 -0400 Subject: color: add color_set helper for copying raw colors To set up default colors, we sometimes strcpy() from the default string literals into our color buffers. This isn't a bug (assuming the destination is COLOR_MAXLEN bytes), but makes it harder to audit the code for problematic strcpy calls. Let's introduce a color_set which copies under the assumption that there are COLOR_MAXLEN bytes in the destination (of course you can call it on a smaller buffer, so this isn't providing a huge amount of safety, but it's more convenient than calling xsnprintf yourself). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- color.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'color.c') diff --git a/color.c b/color.c index 22782f8ba3..8f85153d0d 100644 --- a/color.c +++ b/color.c @@ -145,6 +145,11 @@ int color_parse(const char *value, char *dst) return color_parse_mem(value, strlen(value), dst); } +void color_set(char *dst, const char *color_bytes) +{ + xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes); +} + /* * Write the ANSI color codes for "c" to "out"; the string should * already have the ANSI escape code in it. "out" should have enough -- cgit v1.2.3