Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bugzilla DB migration completed. Please report issues to Infra team via email via infra@gentoo.org or IRC
Bug 723422 - app-portage/portage-utils: main.c: Object vars_to_read has static storage duration and non-constant initializers
Summary: app-portage/portage-utils: main.c: Object vars_to_read has static storage dur...
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Unclassified (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Fabian Groffen
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2020-05-16 18:18 UTC by Guillermo D. H.
Modified: 2020-08-17 15:05 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guillermo D. H. 2020-05-16 18:18:00 UTC
Currently, array vars_to_read is defined in file scope, so it has static storage duration, and its elements must have initializers that are constant expressions. However, the initializers for members 'name_len' and 'value_len' contain a function call (to strlen()), and are therefore not constant expressions:

https://gitweb.gentoo.org/proj/portage-utils.git/tree/main.c?id=a0780928edc76543e63709c915fb7d581bd13291

While GCC happens to compile the package when it uses its builtin strlen(), it does correctly diagnose all instances of _Q_EVS and _Q_EVB use when building with option -fno-builtin-strlen ("error: initializer element is not constant").

Since all uses of strlen() have character string literals as arguments, I suggest making the code conforming by replacing strlen(x) with sizeof(x) - 1, which yields the correct result in this case, but is also a constant expression.

https://forums.gentoo.org/viewtopic-t-1113224.html
Comment 1 Larry the Git Cow gentoo-dev 2020-05-16 18:51:21 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b71b21d13405857d95cff02551558fed0c4d356e

commit b71b21d13405857d95cff02551558fed0c4d356e
Author:     Fabian Groffen <grobian@gentoo.org>
AuthorDate: 2020-05-16 18:50:19 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2020-05-16 18:50:19 +0000

    main: use sizeof iso strlen to enforce compile-time constants
    
    Bug: https://bugs.gentoo.org/723422
    Signed-off-by: Fabian Groffen <grobian@gentoo.org>

 main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Comment 2 Guillermo D. H. 2020-05-16 19:02:42 UTC
(In reply to Larry the Git Cow from comment #1)
> commit b71b21d13405857d95cff02551558fed0c4d356e
> Author:     Fabian Groffen <grobian@gentoo.org>

Thanks, Fabian, but Q_EV() still has a non-constant initializer for member 'name:len':

.name_len = strlen(#V), \
Comment 3 Larry the Git Cow gentoo-dev 2020-05-17 08:15:06 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2f5a42a9d667ac3625be33ae90faf650d4f51912

commit 2f5a42a9d667ac3625be33ae90faf650d4f51912
Author:     Fabian Groffen <grobian@gentoo.org>
AuthorDate: 2020-05-17 08:14:00 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2020-05-17 08:14:00 +0000

    main: replace another instance of strlen with sizoef() - 1
    
    As pointed out by Guillermo D. H. there was another instance of strlen
    used on a constant.
    
    Bug: https://bugs.gentoo.org/723422
    Signed-off-by: Fabian Groffen <grobian@gentoo.org>

 main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 4 Guillermo D. H. 2020-05-17 18:38:16 UTC
(In reply to Larry the Git Cow from comment #3)
> commit 2f5a42a9d667ac3625be33ae90faf650d4f51912
> Author:     Fabian Groffen <grobian@gentoo.org>
app-portage/portage-utils-9999 builds for me now even if -fno-builtin-strlen is set in CFLAGS. Thank you.
Comment 5 Larry the Git Cow gentoo-dev 2020-08-17 15:05:54 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=aa66d89f08797cc9d4f48e670fc277a57d1873bf

commit aa66d89f08797cc9d4f48e670fc277a57d1873bf
Author:     Fabian Groffen <grobian@gentoo.org>
AuthorDate: 2020-08-17 15:05:29 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2020-08-17 15:05:29 +0000

    app-portage/portage-utils-0.89: version bump
    
    Closes: https://bugs.gentoo.org/711896
    Closes: https://bugs.gentoo.org/698462
    Closes: https://bugs.gentoo.org/723422
    Package-Manager: Portage-2.3.103, Repoman-2.3.23
    Signed-off-by: Fabian Groffen <grobian@gentoo.org>

 app-portage/portage-utils/Manifest                     |  2 +-
 ...age-utils-0.80.ebuild => portage-utils-0.89.ebuild} | 18 +-----------------
 2 files changed, 2 insertions(+), 18 deletions(-)