summaryrefslogtreecommitdiff
path: root/src/fe-common/core/formats.c
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2017-05-05 14:45:13 +0200
committerailin-nemui <ailin-nemui@users.noreply.github.com>2018-01-06 00:26:48 +0100
commit451019d05dfabbac2463f0d835c5113ac140c5c4 (patch)
tree78e0f0c108e09a3bfc590a5f2bd30ae2e28776aa /src/fe-common/core/formats.c
parente405330e04dc344797f00c12cf8fd7f63b17e0e4 (diff)
downloadirssi-451019d05dfabbac2463f0d835c5113ac140c5c4.zip
make format_real_length left-collecting
Diffstat (limited to 'src/fe-common/core/formats.c')
-rw-r--r--src/fe-common/core/formats.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c
index 37db6f7c..4c819c2d 100644
--- a/src/fe-common/core/formats.c
+++ b/src/fe-common/core/formats.c
@@ -480,27 +480,30 @@ int format_real_length(const char *str, int len)
start = str;
tmp = g_string_new(NULL);
- while (*str != '\0' && len > 0) {
+ while (*str != '\0') {
+ oldstr = str;
if (*str == '%' && str[1] != '\0') {
str++;
if (*str != '%') {
adv = format_expand_styles(tmp, &str, NULL);
- str += adv;
- if (adv)
- continue;
- }
-
- /* %% or unknown %code, written as-is */
- if (*str != '%') {
- if (--len == 0)
- break;
+ if (adv) {
+ str += adv;
+ continue;
+ }
+ /* discount for unknown % */
+ if (--len < 0) {
+ str = oldstr;
+ break;
+ }
+ oldstr = str;
}
}
- oldstr = str;
len -= string_advance(&str, utf8);
- if (len < 0)
+ if (len < 0) {
str = oldstr;
+ break;
+ }
}
g_string_free(tmp, TRUE);