htop-dev / htop

htop - an interactive process viewer
https://htop.dev/
GNU General Public License v2.0
6.43k stars 439 forks source link

cppcheck output #1214

Open polluks opened 1 year ago

polluks commented 1 year ago

cppcheck -q -v . --enable=all -DHAVE_OPENVZ
[Process.h:26]: (error) syntax error
[freebsd/FreeBSDProcessList.c:464]: (error) Array 'jiov[4]' accessed at index 4, which is out of bounds.
[generic/fdstat_sysctl.c:81]: (error) #error Unknown platform: Please implement proper way to query open/max file information
[linux/LinuxProcessList.c:108]: (style) The scope of the variable 'nibble' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
    int i = 0;
    if (x) {
        // it's safe to move 'int i = 0;' here
        for (int n = 0; n < 10; ++n) {
            // it is possible but not safe to move 'int i = 0;' here
            do_something(&i);
        }
    }
}
When you see this message it is always safe to reduce the variable scope 1 level.
[linux/LinuxProcessList.c:108]: (style) The scope of the variable 'letter' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
    int i = 0;
    if (x) {
        // it's safe to move 'int i = 0;' here
        for (int n = 0; n < 10; ++n) {
            // it is possible but not safe to move 'int i = 0;' here
            do_something(&i);
        }
    }
}
When you see this message it is always safe to reduce the variable scope 1 level.
BenBE commented 1 year ago
$ cppcheck -q -v . --enable=all -DHAVE_OPENVZ

Actually there's no need to pass any flags, as all flags are provided via config.h. Additional flags should, if given, align with what make passes to gcc in CFLAGS.

[Process.h:26]: (error) syntax error

cppcheck doesn't understand proper C99 syntax …

[freebsd/FreeBSDProcessList.c:464]: (error) Array 'jiov[4]' accessed at index 4, which is out of bounds.

Please elaborate where this access should be … I think that's another false-positive from CPPCheck …

[generic/fdstat_sysctl.c:81]: (error) #error Unknown platform: Please implement proper way to query open/max file information

This is intentional as generic/fdstat_sysctl.c is not used on platforms that don't need it (like FreeBSD) … Have a look at Makefile.am for details …

[linux/LinuxProcessList.c:108]: (style) The scope of the variable 'nibble' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops.
When you see this message it is always safe to reduce the variable scope 1 level.
[linux/LinuxProcessList.c:108]: (style) The scope of the variable 'letter' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops.
When you see this message it is always safe to reduce the variable scope 1 level.

Intentional and not a bug to have that variable visible for the whole function lifetime. Also common paradigm for C89/C99. Not reducing the scope of those two variables makes the code actually more readable IMO.