RT-Thread / RT-Thread/rt-thread

gcc10.3.1 报提醒 warning: 'strncpy' specified bound depends on the length of the source argument

Open
#6,668 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
12.2k
Forks
5.4k
Avg merge
4d 12h
Merged PRs (30d)
40

Description

版本 SHA-1: f57eb4feb5ee4856299058058eff15593ac0570d
gcc10.3.1 报提醒

#define HAVE_NEWLIB_H 1
#define LIBC_VERSION "newlib 4.1.0"

#define HAVE_SYS_SIGNAL_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_PTHREAD_H 1

#define HAVE_FDSET 1
#define HAVE_SIGACTION 1
#define HAVE_SIGEVENT 1
#define HAVE_SIGINFO 1
#define HAVE_SIGVAL 1
#define GCC_VERSION_STR "10.3.1 20210824 (release)"
#define STDC "2011"
F:\folder\rtt\rt-thread\include/rtthread.h:634:37: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  634 | #define rt_strncpy(dest, src, n)    strncpy(dest, src, n)
      |                                     ^~~~~~~~~~~~~~~~~~~~~
F:\folder\rtt\rt-thread\components\drivers\spi\spi_flash_sfud.c:326:9: note: in expansion of macro 'rt_strncpy'
  326 |         rt_strncpy(spi_flash_dev_name_bak, spi_flash_dev_name, rt_strlen(spi_flash_dev_name));
      |         ^~~~~~~~~~
F:\folder\rtt\rt-thread\include/rtthread.h:634:37: warning: 'CC build\kernel\components\libc\compilers\common\cctype.o
strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  634 | #define rt_strncpy(dest, src, n)    strncpy(dest, src, n)
      |                                     ^~~~~~~~~~~~~~~~~~~~~
F:\folder\rtt\rt-thread\components\drivers\spi\spi_flash_sfud.c:327:9: note: in expansion of macro 'rt_strncpy'
  327 |         rt_strncpy(spi_dev_name_bak, spi_dev_name, rt_strlen(spi_dev_name));
      |         ^~~~~~~~~~

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in components/drivers/spi/spi_flash_sfud.c at lines 326-327 and inspect the rt_strncpy macro in include/rtthread.h:634. Reproduce the warning with the repository revision f57eb4feb5ee4856299058058eff15593ac0570d and GCC 10.3.1. Done means the reported warning is addressed while the affected build continues to succeed.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.