Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many string truncation warnings with newer GCC #641

Closed
jphickey opened this issue Apr 27, 2020 · 0 comments · Fixed by #642 or #692
Closed

Many string truncation warnings with newer GCC #641

jphickey opened this issue Apr 27, 2020 · 0 comments · Fixed by #642 or #692
Assignees
Milestone

Comments

@jphickey
Copy link
Contributor

Describe the bug
Ubuntu has released 20.04 LTS which includes GCC 9.3.0. When using this compiler it implements a much stricter (and often over-zealous) checking of string ops.

For instance:

In file included from /usr/include/string.h:495,
                 from /home/joe/code/cfecfs/github/cfe/fsw/cfe-core/src/es/cfe_es_cds.c:49:
In function ‘strncpy’,
    inlined from ‘CFE_ES_RegisterCDSEx’ at /home/joe/code/cfecfs/github/cfe/fsw/cfe-core/src/es/cfe_es_cds.c:299:12:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 38 equals destination size [-Werror=stringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To Reproduce
Build code with default config using GCC 9.3.0, with optimization enabled and full warnings.

Expected behavior
Code should build cleanly.

System observed on:
Ubuntu 20.04 LTS 64 bit.

Additional context
Unfortunately GCC warns about ANY construct which MIGHT truncate, even if truncation is anticipated and handled properly in the code. GCC now declares that one is never allowed to truncate anything in a C library string operation, even if you read the manual and coded it correctly per the C spec, it's still wrong to GCC9.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

jphickey added a commit to jphickey/cFE that referenced this issue Apr 27, 2020
Ensure clean build, no warnings on string operations using GCC 9.3.0.

Some string ops were genuinely incorrect (particularly in UT) but some
were perfectly OK and handled correctly per the C spec.  In particular
the new "rules" that GCC9 warns about make the strncat library function
(and some others) somewhat off-limits even if used correctly.
jphickey added a commit to jphickey/cFE that referenced this issue Apr 27, 2020
Ensure clean build, no warnings on string operations using GCC 9.3.0.

Some string ops were genuinely incorrect (particularly in UT) but some
were perfectly OK and handled correctly per the C spec.  In particular
the new "rules" that GCC9 warns about make the strncat library function
(and some others) somewhat off-limits even if used correctly.
astrogeco added a commit that referenced this issue May 8, 2020
@skliper skliper added this to the 6.8.0 milestone May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants