From 839b199f966b760cec9400e447461be086bd962d Mon Sep 17 00:00:00 2001
From: Wu Jianhua <jianhua.wu@intel.com>
Date: Mon, 17 Jan 2022 13:43:16 +0800
Subject: [PATCH 4/5] avutil/vulkan: don't use strlen as loop condition

We don't need the strlen to get the size of string, for
there is a null terminated condition of C-style string.

And deal with the last line without line feed notation
to output correct shader text for shader_vulkan filter.

Signed-off-by: Wu Jianhua <jianhua.wu@intel.com>
---
 libavutil/vulkan.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 00df08b55e..0446e822af 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -833,14 +833,20 @@ void ff_vk_print_shader(void *ctx, FFVkSPIRVShader *shd, int prio)
     AVBPrint buf;
     av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
 
-    for (int i = 0; i < strlen(p); i++) {
-        if (p[i] == '\n') {
+    while (*p) {
+        if (*p++ == '\n') {
             av_bprintf(&buf, "%i\t", ++line);
-            av_bprint_append_data(&buf, start, &p[i] - start + 1);
-            start = &p[i + 1];
+            av_bprint_append_data(&buf, start, p - start);
+            start = p;
         }
     }
 
+    /* Last line without '\n' */
+    if (p != start) {
+        av_bprintf(&buf, "%i\t", ++line);
+        av_bprintf(&buf, "%s\n", start);
+    }
+
     av_log(ctx, prio, "Shader %s: \n%s", shd->name, buf.str);
     av_bprint_finalize(&buf, NULL);
 }
-- 
2.25.1

