]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
utf8: let utf8_console_width() handle NULL strings somewhat reasonably
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Apr 2024 15:41:38 +0000 (17:41 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 14 Jun 2024 23:46:42 +0000 (00:46 +0100)
src/basic/utf8.c

index b5711f430014e49e76d9ff6c32efc667c0bc50aa..15deef1ffd0b0c8fcd769fef9a361482f89719bc 100644 (file)
@@ -597,11 +597,14 @@ size_t utf8_n_codepoints(const char *str) {
 }
 
 size_t utf8_console_width(const char *str) {
-        size_t n = 0;
+
+        if (isempty(str))
+                return 0;
 
         /* Returns the approximate width a string will take on screen when printed on a character cell
          * terminal/console. */
 
+        size_t n = 0;
         while (*str) {
                 int w;