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

Trying to understand some code logic #17

Open
smooge opened this issue Feb 7, 2024 · 1 comment
Open

Trying to understand some code logic #17

smooge opened this issue Feb 7, 2024 · 1 comment

Comments

@smooge
Copy link

smooge commented Feb 7, 2024

I started going over the code with cppcheck to learn more about cppcheck, and while I expect it is overly pedantic I came up with some questions

        if (dev < 0xf)
                snprintf(str, sizeof(str), "phy:%d", dev);
        else if (dev == 0xf)
                return "serdes";
        else if (dev)
                snprintf(str, sizeof(str), "port:%d", dev - 0x10);
        else if (dev == 0x1b)
                return "global:1";
        else if (dev == 0x1c)
                return "global:2";
        else if (dev == 0x1d)
                return "global:3";
        else
                snprintf(str, sizeof(str), "port:RESERVED(%#.2x)", dev);

cppcheck complains about the logic in different ways which I am not sure is the right complaints:

print_mv6.c:54:11: style: Condition 'dev' is always true [knownConditionTrueFalse]
 else if (dev)
          ^
print_mv6.c:52:15: note: Assuming that condition 'dev==0xf' is not redundant
 else if (dev == 0xf)
              ^
print_mv6.c:54:11: note: Condition 'dev' is always true
 else if (dev)
          ^
print_mv6.c:56:15: style: Condition 'dev==0x1b' is always false [knownConditionTrueFalse]
 else if (dev == 0x1b)
              ^
... more deleted

Reading through the logic, I read it as if dev is less than 0xf then print A else if dev == 0xf else if dev and the rest of the if would get skipped because the first else says dev must exist and must be greater than 0xf. but this could be me missing another C should know item from being in python-land too long.

If you have time could you explain what I am probably missing in the code?

@wkz
Copy link
Owner

wkz commented Feb 19, 2024

You're not missing anything. This is just really bad code from my side 😀

The whole mv6 program should really be torn out of this tool, since it only ever worked in combination with a patched kernel that was never publicized anywhere. Truth be told, I'm having a hard time caring about this project, since I've moved to use mdio-tools instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants