File 0244-escript-Avoid-warning-about-truncated-output-in-strn.patch of Package erlang

From ba763d9dc2979d824006d96f182ebdb562191e5f Mon Sep 17 00:00:00 2001
From: Frej Drejhammar <frej.drejhammar@gmail.com>
Date: Tue, 11 Apr 2023 10:24:32 +0200
Subject: [PATCH 1/2] escript: Avoid warning about truncated output in strncpy
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GCC warns about how `strncpy` is used in `erts/etc/common/escript.c`:

```
escript.c: In function ‘main’:
escript.c:289:17: warning: ‘__builtin_strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
  289 |                 strncpy(dir, beg, sz);
      |                 ^
In function ‘find_prog’,
    inlined from ‘main’ at escript.c:483:25:
escript.c:282:26: note: length computed here
  282 |                     sz = strlen(beg);
```

The warning is triggered as GCC understands that, as `sz =
strlen(beg)`, `strncpy` will never see and copy a terminating nul
character to `dir`.

As we manually null-terminate `dir`, by `dir[sz] = '\0';` on the line
following `strncpy` we can avoid the warning, and speed up the copy a
little (there is no need to look for a nul terminator), by using a
plain `memcpy`.
---
 erts/etc/common/escript.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c
index fe474338fb..c7418b2ace 100644
--- a/erts/etc/common/escript.c
+++ b/erts/etc/common/escript.c
@@ -286,7 +286,7 @@ find_prog(char *origpath)
                     beg = end + 1;
                     continue;
                 }
-                strncpy(dir, beg, sz);
+                memcpy(dir, beg, sz);
                 dir[sz] = '\0';
                 beg = end + 1;
 
-- 
2.35.3

openSUSE Build Service is sponsored by