diff options
author | Thomas Adam <thomas@xteddy.org> | 2016-01-31 12:01:09 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2016-01-31 12:01:09 +0000 |
commit | 5fce21728e61b0d2be39f3bc9eba28d5f400f61e (patch) | |
tree | e056480e3d798bf72d99f049f492b73df72d86c1 /format.c | |
parent | 404379049a4cb5480c2b1c19634c869e46feb220 (diff) | |
parent | fa64b89ad7af8daf04c50b54fe8b45411750149e (diff) | |
download | rtmux-5fce21728e61b0d2be39f3bc9eba28d5f400f61e.tar.gz rtmux-5fce21728e61b0d2be39f3bc9eba28d5f400f61e.tar.bz2 rtmux-5fce21728e61b0d2be39f3bc9eba28d5f400f61e.zip |
Merge branch 'obsd-master'
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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. */ |