Fix gcc warnings#287
Conversation
|
The CI failures look to be caused by libvalkey using a different version of the strerror_r function than PCP. PCP defines _GNU_SOURCE while libvalkey does not. This leads to libvalkey using the POSIX version that will always populate the buffer and return an int. The GNU version returns a char* and might not write to the buffer. I'm looking into how to work this out, but open to suggestions :). |
|
@sfeifer I think the simplest fix for ... | warning: ignoring return value of ‘strerror_r’ ... will be to "cast" the return value to (void) and continue right on ignoring it as before. |
I tried that earlier and agree that it would work for the POSIX strerror_r, but it does not silence the warning for the GNU version. I think this is because the return of the GNU strerror_r function needs to be checked in case the buffer was not populated as the return will contain the error string. Here's the error in valkey.c with the void cast: |
9c23537 to
6f77d67
Compare
Signed-off-by: Sam Feifer <sfeifer@redhat.com>
6f77d67 to
3af8929
Compare
|
I changed how libvalkey is compiled in pcp to use the -U_GNU_SOURCE flag, which results in the POSIX strerror_r function being used. With this change, the ignored return value warnings are no longer present without any changes to the libvalkey sources (i.e. no modifications needed to net.c or valkey.c). I have now updated the PR to only fix the shadowed declaration warnings in async.c and sds.c. |
|
Nice, I don't see this with I have found some statements that |
|
I think the drawback of using -Wshadow is the additional noise. The warnings can help point out where a variable should be named something different to avoid confusion. There might be scenarios, though, where we want to keep the variable name as is leading to a warning that will be there every time libvalkey is compiled. |
|
Sounds good, lets merge this. Thanks! |
Several gcc warnings were found in the libvalkey sources when building Performance Co-Pilot with libvalkey. The async.c and sds.c files have shadowed declaration warnings. In valkey.c and net.c, there are ignored return values. This PR fixes those warnings.
async.c:
sds.c:
valkey.c:
net.c:
To fix the shadowed declarations in async.c and sds.c, I just renamed the variables.
For the ignored returned values, I assigned the return of strerror_r to a char *, errmsg. There is then a check to make sure errmsg is the same as what is put into the buffer when strerror_r executes. If not, the buffer will be populated with the string pointed to by errmsg. My understanding of strerror_r is that it could return a pointer to a string rather than writing to the buffer. This new logic handles that case.