From b400d3ca901d789d6abd56303926099df27c30af Mon Sep 17 00:00:00 2001 From: arxhr007 Date: Thu, 29 Oct 2026 21:57:35 +0530 Subject: [PATCH] Separator: fixes an infinite loop when the string is empty --- CHANGELOG.md | 1 + src/modules/separator/separator.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22d2ef918..7be012f982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bugfixes: * Improved uptime detection on SunOS via kstat. (#2674, Uptime, SunOS) * Fixed substring formatting returning the remaining string when a negative end index is before the start of the string. (General) +* Fixed an infinite loop when the separator string is empty. (#2689, Separator) # 2.70.0 diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index c8ac4b337a..f465f82c68 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -32,9 +32,10 @@ bool ffPrintSeparator(FFSeparatorOptions* options) { } else { uint32_t wcsLength = ffUtf8StrWidth(options->string.chars, options->string.length); - int remaining = (int) titleLength; + // An empty string can't fill the line: there is nothing to repeat + int remaining = wcsLength > 0 ? (int) titleLength : 0; // Write the whole separator as often as it fits fully into titleLength - for (; remaining >= (int) wcsLength; remaining -= (int) wcsLength) { + for (; wcsLength > 0 && remaining >= (int) wcsLength; remaining -= (int) wcsLength) { ffStrbufWriteTo(&options->string, stdout); }