[ZBX-15898] Compilation warning in function vfs_dir_count() Created: 2019 Mar 29 Updated: 2019 Apr 10 Resolved: 2019 Apr 09 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Agent (G) |
Affects Version/s: | 4.0.6 |
Fix Version/s: | 4.0.7rc1, 4.2.1rc1, 4.4.0alpha1, 4.4 (plan) |
Type: | Problem report | Priority: | Minor |
Reporter: | Alexander Vladishev | Assignee: | Andrejs Kozlovs |
Resolution: | Fixed | Votes: | 0 |
Labels: | codequality, compilation | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
Debian GNU/Linux 6.0 amd64 |
Issue Links: |
|
||||||||
Team: | Team A | ||||||||
Sprint: | Sprint 50 (Mar 2019), Sprint 51 (Apr 2019) | ||||||||
Story Points: | 0.125 |
Description |
dir.c: In function ‘vfs_dir_count’: dir.c:1069: warning: integer constant is too large for ‘long’ type |
Comments |
Comment by Andris Mednis [ 2019 Apr 05 ] |
I was able to get this warning only on 32-bit Linux, with -Wlong-long added to GCC 8.3.0 options: dir.c: In function ‘vfs_dir_count’: dir.c:1069:2: warning: integer constant is too large for ‘long’ type [-Wlong-long] zbx_uint64_t min_size = 0, max_size = 0x7FFFffffFFFFffff; ^~~~~~~~~~~~ With proposed fix the warning changes to dir.c: In function ‘vfs_dir_count’: dir.c:1069:52: warning: use of C99 long long integer constant [-Wlong-long] zbx_uint64_t min_size = 0, max_size = __UINT64_C(0x7FFFffffFFFFffff); ^~~~~~~~~~~~~~~~~~ (simple warning that a C99 feature is used). On 64-bit Linux and 64-bit Windows 10 I could not reproduce the warning. |
Comment by Glebs Ivanovskis [ 2019 Apr 05 ] |
Off-topic. Why does the constant start with 7? It seems to be used as "infinity", all Fs would be more logical. |
Comment by Andris Mednis [ 2019 Apr 08 ] |
The reason might be comparing it with file size: zbx_stat_t status; ... && (zbx_uint64_t)status.st_size <= max_size) && "man 2 stat" shows The stat structure ... struct stat { ... off_t st_size; /* Total size, in bytes */ ... Where to find the complete definition of off_t type? tells that "... off_t shall be signed integer types." |
Comment by Glebs Ivanovskis [ 2019 Apr 08 ] |
Well, it is still casted/promoted to 64-bit unsigned type before comparison. |
Comment by Glebs Ivanovskis [ 2019 Apr 08 ] |
My point is that Zabbix uses uint64_t on UNIX'es to #define zbx_uint64_t. This is a C99 feature. C99 also provides INT64_MAX, UINT64_MAX and so on. Why not use them (instead of counting "f" letters)? I think there is a good chance that compiler supports both uint64_t and UINT64_MAX at the same time even if it does not provide full C99 support. |
Comment by Andrejs Kozlovs [ 2019 Apr 08 ] |
Fixed in:
|