# Compiler warning about strncpy

**URL:** <https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568>\
**Category:** Help\
**Tags:** agent, agent-collectors\
**Created:** [July 23, 2021, 7:17pm UTC](https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568 "2021-07-23T19:17:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cho](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@cho](https://community.netdata.cloud/u/cho)\
**Post date:** [July 23, 2021, 7:17pm UTC](https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568/1 "2021-07-23T19:17:13Z")

</div>

## Environment

Fedora 29, gcc 8.3.1, running Kickstart downloaded 2021-07-23

## Problem/Question

While compiling, the compiler emitted these warnings:

```auto
  GEN netdata
In function 'update_disk_table',
    inlined from 'read_local_disks' at collectors/ebpf.plugin/ebpf_disk.c:347:13:
collectors/ebpf.plugin/ebpf_disk.c:292:9: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
         strncpy(disk_list->family, name, length);
         ^
collectors/ebpf.plugin/ebpf_disk.c: In function 'read_local_disks':
collectors/ebpf.plugin/ebpf_disk.c:288:18: note: length computed here
         length = strlen(name);
                  ^
In function 'update_disk_table',
    inlined from 'read_local_disks' at collectors/ebpf.plugin/ebpf_disk.c:347:13:
collectors/ebpf.plugin/ebpf_disk.c:280:9: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
         strncpy(w->family, name, length);
         ^
collectors/ebpf.plugin/ebpf_disk.c: In function 'read_local_disks':
collectors/ebpf.plugin/ebpf_disk.c:276:18: note: length computed here
         length = strlen(name);
                  ^

```

## What I expected to happen

No warnings. 🙂

---

<div class="post-metadata">

**Author:** ![ilyam8](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.netdata.cloud/ilyam8/32/134_2.png) [@ilyam8](https://community.netdata.cloud/u/ilyam8)\
**Post date:** [July 26, 2021, 8:13am UTC](https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568/2 "2021-07-26T08:13:33Z")

</div>

Hey, @cho 👋 Thanks for reporting!

@Thiago_Marques_0 please, take a look.

---

<div class="post-metadata">

**Author:** ![Thiago\_Marques\_0](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.netdata.cloud/thiago_marques_0/32/281_2.png) [@Thiago\_Marques\_0](https://community.netdata.cloud/u/Thiago_Marques_0)\
**Post date:** [July 26, 2021, 10:54am UTC](https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568/3 "2021-07-26T10:54:03Z")

</div>

Hello @cho ,

This looks like a problem only with this gcc version, because I am not having it with latest gcc. I will install the same fedora version to fix this for old versions. Thank you to report!

Best regards,

Thiago

---

<div class="post-metadata">

**Author:** ![Thiago\_Marques\_0](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.netdata.cloud/thiago_marques_0/32/281_2.png) [@Thiago\_Marques\_0](https://community.netdata.cloud/u/Thiago_Marques_0)\
**Post date:** [August 2, 2021, 1:52am UTC](https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568/4 "2021-08-02T01:52:25Z")

</div>

Hello @cho ,

Firstly sorry for the delay, but I was on vacation when I saw your message.

I observed that this warning given by gcc 8.x does not make much sense, because we are testing the source size before to do the copy, as you can see in this [code](https://github.com/netdata/netdata/blob/e2303fea720871ef568a175d8a50a478154a1db8/collectors/ebpf.plugin/ebpf_disk.c#L288-L292).

After to install the same Fedora 29 and get the same gcc version, I could replicate the problem, but when I am compiling with gcc 10.3.0, I do not have more warnings, so I think GNU fixed the bug with their compile. On Monday I will take a look again and try to remove this warning for old GCCs.

Best Regards!

---

<div class="post-metadata">

**Author:** ![Thiago\_Marques\_0](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.netdata.cloud/thiago_marques_0/32/281_2.png) [@Thiago\_Marques\_0](https://community.netdata.cloud/u/Thiago_Marques_0)\
**Post date:** [August 2, 2021, 7:27pm UTC](https://community.netdata.cloud/t/compiler-warning-about-strncpy/1568/5 "2021-08-02T19:27:15Z")

</div>

PR [Remove warning when GCC 8.x is used by thiagoftsm · Pull Request #11389 · netdata/netdata · GitHub](https://github.com/netdata/netdata/pull/11389) was made to fix this issue.  
Thank you @cho !
