This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: gcc 7.3 causes a warning when compiling getpath.c in python 2.7
Type: Stage: resolved
Components: Build Versions: Python 2.7
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: tzickel, vstinner
Priority: normal Keywords:

Created on 2018-07-31 19:25 by tzickel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg322809 - (view) Author: (tzickel) * Date: 2018-07-31 19:25
When compiling on ubuntu 18.04 the 2.7 branch, I get this warning:

gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -DPYTHONPATH='":plat-linux2:lib-tk:lib-old"' \
        -DPREFIX='"/usr/local"' \
        -DEXEC_PREFIX='"/usr/local"' \
        -DVERSION='"2.7"' \
        -DVPATH='""' \
        -o Modules/getpath.o ./Modules/getpath.c
In file included from /usr/include/string.h:494:0,
                 from Include/Python.h:38,
                 from ./Modules/getpath.c:3:
In function 'strncpy',
    inlined from 'joinpath' at ./Modules/getpath.c:202:5,
    inlined from 'search_for_prefix' at ./Modules/getpath.c:265:9,
    inlined from 'calculate_path' at ./Modules/getpath.c:505:8:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: '__builtin_strncpy': specified size between 9223372036854779906 and 18446744073709551615 exceeds maximum object size
9223372036854775807 [-Wstringop-overflow=]
   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));

I think it's because the compiler can't reason that Py_FatalError aborts the program, and thus not overflow strncpy.

Since there are about 3-4 warnings while building, maybe we should add a manual return after Py_FatalError in joinpath ?
msg322812 - (view) Author: (tzickel) * Date: 2018-07-31 19:50
Changing Py_FatalError prototype to add: __attribute__((noreturn)) also stops the warning.
msg353253 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-26 01:14
This issue is only a compiler warning, you can ignore it.

Python 2.7 is close to its end of life: I close the issue. I don't think that it's worth it to spend time trying to fix this old issue in 2.7.

In the master branch, Py_FatalError uses __attribute__((noreturn)).
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78481
2019-09-26 01:14:15vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg353253

resolution: wont fix
stage: resolved
2018-07-31 19:50:31tzickelsetmessages: + msg322812
2018-07-31 19:25:15tzickelcreate