fix compiler warnings on EL6,EL7,EL8#76
fix compiler warnings on EL6,EL7,EL8#76pbiering wants to merge 1 commit intonaemon:masterfrom pbiering:fix-some-compiler-warnings
Conversation
| bool accepts(void *data); | ||
| void combineFilters(int count, int andor); | ||
| unsigned numFilters() { return _subfilters.size(); } | ||
| int numFilters() { return _subfilters.size(); } // satisfy -Wsign-compare |
There was a problem hiding this comment.
But we cannot have a negative number of filters. I think we want unsigned here. On what line does it complain about the comparison?
| int num_cached_log_messages = 0; | ||
|
|
||
| LogCache::LogCache(unsigned long max_cached_messages) | ||
| LogCache::LogCache(long max_cached_messages) // satisfy -Wsign-compare |
There was a problem hiding this comment.
Unsigned seems correct to me, should look at the comparison instead
| } | ||
|
|
||
| void LogCache::setMaxCachedMessages(unsigned long m) | ||
| void LogCache::setMaxCachedMessages(long m) // satisfy -Wsign-compare |
There was a problem hiding this comment.
Unsigned seems correct to me, should look at the comparison instead
| ++it) | ||
| { | ||
| Logfile *log = it->second; | ||
| // Logfile *log = it->second; // satisfy -Wunused-variable |
| host *host = svc->host_ptr; | ||
| servicesmember *svc_member = host->services; | ||
| double check_interval = 1; | ||
| // double check_interval = 1; // satisfy -Wunused-variable |
| contact *auth_user = query->authUser(); | ||
| int32_t result = 0; | ||
| int lt; | ||
| // int lt; // satisfy -Wunused-variable |
| void TableHosts::answerQuery(Query *query) | ||
| { | ||
| struct hostbygroup **_hg_tmp_storage = (struct hostbygroup **)&(query->table_tmp_storage); | ||
| // struct hostbygroup **_hg_tmp_storage = (struct hostbygroup **)&(query->table_tmp_storage); // satisfy -Wunused-variable |
jacobbaungard
left a comment
There was a problem hiding this comment.
Overall looks good, but could you have a look at all the changes from unsigned to signed. I think all cases it makes sense to have unsigned, as negative numbers makes no sense in that context.
in underlying resulting assembler code, usually comparison of integers are done by substracting them (and therefore converting them to signed integer before) and check whether result is greater/equal/lower than zero. Looks like compilers get more strict here to prevent any accidents by substracting integers which have value >= 2^(bitlength-1), because then the bit for the +/- get lost. You can avoid the compiler warning by casting during comparison, but this is also not a nice way and can cause issues for same reason. |
|
What I am saying is: We should use consistent types throughout the source, and it makes no sense to change an value which is intrinsically non-negative to a signed integer, just because somewhere we are doing a comparison with a signed integer. Instead we should ensure the other variable we are comparing with is also unsigned. For example rather than changing _max_cached_messages to |
feel free to fix the other side...I have only tried to fix where compiler warned me -> cherry pick the other valid changes and adjust the others... |
split-out of #71