aboutsummaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2016-02-05 10:08:55 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2016-02-05 10:08:55 +0000
commit07c23ccc05314f5d351cb70d08a9256e15d105d9 (patch)
tree70a8a25daa06d7330bfabba5dbe9be8fd9fc43c8 /format.c
parent2130a07b70db7df8d57b9cad96a6866203daacad (diff)
parent26f899be109d2b7e8c8fae4ca8e3baaccf8d2655 (diff)
downloadrtmux-07c23ccc05314f5d351cb70d08a9256e15d105d9.tar.gz
rtmux-07c23ccc05314f5d351cb70d08a9256e15d105d9.tar.bz2
rtmux-07c23ccc05314f5d351cb70d08a9256e15d105d9.zip
Merge branch 'master' of github.com:tmux/tmux
Diffstat (limited to 'format.c')
-rw-r--r--format.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/format.c b/format.c
index f7282a61..d263cb0c 100644
--- a/format.c
+++ b/format.c
@@ -701,7 +701,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
char *copy, *copy0, *endptr, *ptr, *found, *new, *value;
char *from = NULL, *to = NULL;
size_t valuelen, newlen, fromlen, tolen, used;
- u_long limit = 0;
+ long limit = 0;
int modifiers = 0, brackets;
/* Make a copy of the key. */
@@ -713,8 +713,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
switch (copy[0]) {
case '=':
errno = 0;
- limit = strtoul(copy + 1, &endptr, 10);
- if (errno == ERANGE && limit == ULONG_MAX)
+ limit = strtol(copy + 1, &endptr, 10);
+ if (errno == ERANGE && (limit == LONG_MIN || limit == LONG_MAX))
break;
if (*endptr != ':')
break;
@@ -830,10 +830,14 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
}
/* Truncate the value if needed. */
- if (limit != 0) {
+ if (limit > 0) {
new = utf8_trimcstr(value, limit);
free(value);
value = new;
+ } else if (limit < 0) {
+ new = utf8_rtrimcstr(value, -limit);
+ free(value);
+ value = new;
}
/* Expand the buffer and copy in the value. */