summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/attributes.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2012-03-17 21:45:25 +0000
committernicm <nicm@openbsd.org>2012-03-17 21:45:25 +0000
commitb7b9dd826f20cf8a3f0e6075bf6662082a32d19f (patch)
tree1ba394c2dcf431b7a785e116c459b6630f0f51ac /usr.bin/tmux/attributes.c
parentAdd a wrap-search option to turn off wrapping of searches in copy (diff)
downloadwireguard-openbsd-b7b9dd826f20cf8a3f0e6075bf6662082a32d19f.tar.xz
wireguard-openbsd-b7b9dd826f20cf8a3f0e6075bf6662082a32d19f.zip
Use snprintf for constructing attribute string, from Tim Ruehsen.
Diffstat (limited to 'usr.bin/tmux/attributes.c')
-rw-r--r--usr.bin/tmux/attributes.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/usr.bin/tmux/attributes.c b/usr.bin/tmux/attributes.c
index 3431b5f2128..d53c0ef8eaa 100644
--- a/usr.bin/tmux/attributes.c
+++ b/usr.bin/tmux/attributes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: attributes.c,v 1.4 2010/05/14 18:56:21 nicm Exp $ */
+/* $OpenBSD: attributes.c,v 1.5 2012/03/17 21:45:25 nicm Exp $ */
/*
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
@@ -26,27 +26,21 @@ const char *
attributes_tostring(u_char attr)
{
static char buf[128];
+ size_t len;
if (attr == 0)
return ("none");
- buf[0] = '\0';
- if (attr & GRID_ATTR_BRIGHT)
- strlcat(buf, "bright,", sizeof (buf));
- if (attr & GRID_ATTR_DIM)
- strlcat(buf, "dim,", sizeof (buf));
- if (attr & GRID_ATTR_UNDERSCORE)
- strlcat(buf, "underscore,", sizeof (buf));
- if (attr & GRID_ATTR_BLINK)
- strlcat(buf, "blink,", sizeof (buf));
- if (attr & GRID_ATTR_REVERSE)
- strlcat(buf, "reverse,", sizeof (buf));
- if (attr & GRID_ATTR_HIDDEN)
- strlcat(buf, "hidden,", sizeof (buf));
- if (attr & GRID_ATTR_ITALICS)
- strlcat(buf, "italics,", sizeof (buf));
- if (*buf != '\0')
- *(strrchr(buf, ',')) = '\0';
+ len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s",
+ attr & GRID_ATTR_BRIGHT ? "bright," : "",
+ attr & GRID_ATTR_DIM ? "dim," : "",
+ attr & GRID_ATTR_UNDERSCORE ? "underscore," : "",
+ attr & GRID_ATTR_BLINK ? "blink," : "",
+ attr & GRID_ATTR_REVERSE ? "reverse," : "",
+ attr & GRID_ATTR_HIDDEN ? "hidden," : "",
+ attr & GRID_ATTR_ITALICS ? "italics," : "");
+ if (len > 0)
+ buf[len - 1] = '\0';
return (buf);
}