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

Fix gcc 8 build warning/error with -O3. #2960

Merged
merged 1 commit into from
Feb 27, 2018

Conversation

Romain-Geissler-1A
Copy link
Contributor

Hi,

I have a small build error/warning when building with gcc 8 and -O3 in CFLAGS/CXXFLAGS:

In member function ‘zmq::msg_t::set_group(char const*, unsigned long)’,
    inlined from ‘zmq::msg_t::set_group(char const*)’ at src/msg.cpp:549:22:
src/msg.cpp:560:13: error: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
     strncpy (u.base.group, group_, length_);
     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/msg.cpp: In member function ‘zmq::msg_t::set_group(char const*)’:
src/msg.cpp:549:22: note: length computed here
     return set_group (group_, strlen (group_));
            ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

Here we don't actually need to call strlen(group_), since strncpy will already stop at the end of the string, and this is what gcc tries to complain about in his cryptic message. Replacing it with the maximum length that fits for a group silences the warning, and has the same end result, without computing the string length both in strlen and strncpy.

Cheers,
Romain

@bluca bluca merged commit 31387f8 into zeromq:master Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants