aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2012-03-18 02:17:20 +0000
committerTiago Cunha <tcunha@gmx.com>2012-03-18 02:17:20 +0000
commitba7278373d4532e7cba530fcb025689ede6aeda3 (patch)
tree143fc2031873132a28638d1fb8bf51dd838c0541
parente4eb43ec718357ad692471683a65ef6aeee3720a (diff)
downloadrtmux-ba7278373d4532e7cba530fcb025689ede6aeda3.tar.gz
rtmux-ba7278373d4532e7cba530fcb025689ede6aeda3.tar.bz2
rtmux-ba7278373d4532e7cba530fcb025689ede6aeda3.zip
Sync OpenBSD patchset 1067:
Use snprintf for constructing attribute string, from Tim Ruehsen.
-rw-r--r--attributes.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/attributes.c b/attributes.c
index d1ce257e..f9871108 100644
--- a/attributes.c
+++ b/attributes.c
@@ -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);
}