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 warnings/errors on GCC 7/8 (-Wclass-memaccess, -Wsign-conversion, -Wformat-overflow) #1323

Merged
merged 3 commits into from
Jul 16, 2018

Conversation

pah
Copy link
Contributor

@pah pah commented Jul 15, 2018

Recent GCC versions warn about using memcpy/memmove to write to a class pointer (-Wclass-memaccess). This has been reported multiple times now, but the suppressions in the master branch are not complete.

This PR avoids the warnings by casting the destination pointer to void* first.

Closes #1086.
Closes #1205.
Closes #1246.

Additional warnings are fixed / suppressed as discovered during testing:

  • Fix -Wsign-conversion warnings/errors (a26267d)
  • Suppress -Wformat-overflow warning/error (1525116)

Recent GCC versions warn about using memcpy/memmove to
write to a class pointer (-Wclass-memaccess).

Avoid the warnings by casting to void* first.

Closes Tencent#1086.
Closes Tencent#1205.
Closes Tencent#1246.
@coveralls
Copy link

coveralls commented Jul 15, 2018

Coverage Status

Coverage increased (+0.001%) to 99.922% when pulling 1525116 on pah:fix-memaccess into 4b4583b on Tencent:master.

pah added 2 commits July 15, 2018 16:01
GCC 8 (incorrectly) warns about sign conversions in (constant)
array size expressions:

error: conversion to 'long unsigned int' from 'int' may
change the sign of the result [-Werror=sign-conversion]
     char schemaBuffer_[128 * 1024];

Make these expressions unsigned by adding a 'u' suffix to
the first operands.
GCC 7 and later warn about overflow/truncation when using
sprintf and related functions with fixed-size buffers.

Suppress the warning in schematest.cpp.
@pah pah changed the title Fix -Wclass-memaccess warnings/errors Fix warnings/errors on GCC 7/8 (-Wclass-memaccess, -Wsign-conversion, -Wformat-overflow) Jul 15, 2018
@miloyip miloyip merged commit 2bbd33b into Tencent:master Jul 16, 2018
@miloyip
Copy link
Collaborator

miloyip commented Jul 16, 2018

Thanks again.

@pah pah deleted the fix-memaccess branch July 16, 2018 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants