path: root/color.h
diff options
authorJeff King <>2015-09-24 21:08:21 (GMT)
committerJunio C Hamano <>2015-10-05 18:08:05 (GMT)
commit7ce4fb948c6d196a376a37840cb80ae95b5897ec (patch)
treea1c203a878cc886cc92ca862a42c2b6d41cdf90e /color.h
parent34fa79a6cde56d6d428ab0d3160cb094ebad3305 (diff)
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 <>
Diffstat (limited to 'color.h')
1 files changed, 7 insertions, 0 deletions
diff --git a/color.h b/color.h
index 7fe77fb..e155d13 100644
--- a/color.h
+++ b/color.h
@@ -75,6 +75,13 @@ extern int color_stdout_is_tty;
int git_color_config(const char *var, const char *value, void *cb);
int git_color_default_config(const char *var, const char *value, void *cb);
+ * Set the color buffer (which must be COLOR_MAXLEN bytes)
+ * to the raw color bytes; this is useful for initializing
+ * default color variables.
+ */
+void color_set(char *dst, const char *color_bytes);
int git_config_colorbool(const char *var, const char *value);
int want_color(int var);
int color_parse(const char *value, char *dst);