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

Use correct size for struct #1355

Merged
merged 1 commit into from
Dec 8, 2020
Merged

Use correct size for struct #1355

merged 1 commit into from
Dec 8, 2020

Conversation

ellert
Copy link
Contributor

@ellert ellert commented Dec 8, 2020

The fix for the gcc 11 compiler warning in commit
8f36753 is incorrect.
Placing the sizeof statement in parenthesis does not correct the bug,
it just obfuscates the code so that the compiler doesn't see it.

The correct fix is to give the unnamed struct a name so that the
sizeof the struct can be used in the calculation.

The fix for the gcc 11 compiler warning in commit
8f36753 is incorrect.
Placing the sizeof statement in parenthesis does not correct the bug,
it just obfuscates the code so that the compiler doesn't see it.

The correct fix is to give the unnamed struct a name so that the
sizeof the struct can be used in the calculation.
@simonmichal
Copy link
Contributor

Indeed you're right, this not an array of pointers, thanks for point it out!

Could you make it: sizeof(Sopts)/sizeof(*Sopts) ?

@ellert
Copy link
Contributor Author

ellert commented Dec 8, 2020

That would work. However, I think the current version is more consistent with the rest od the file:

$ grep -n 'sztab' src/XrdOuc/XrdOucPsx.cc
336:   struct sztab {const char *Key; long long *Val;} szopts[] =
342:   int i, numopts = sizeof(szopts)/sizeof(struct sztab);
$ grep -n 'traceopts' src/XrdOuc/XrdOucPsx.cc
794:    static struct traceopts {const char *opname; int opval;} tropts[] =
800:    int i, trval = 0, numopts = sizeof(tropts)/sizeof(struct traceopts);
$ grep -n 'sopts' src/XrdOuc/XrdOucPsx.cc
706:    static struct sopts {const char *Sopt; const char *Copt; int isT;} Sopts[] =
735:    int i, numopts = sizeof(Sopts)/sizeof(struct sopts);

@abh3 abh3 merged commit 67a2cec into xrootd:master Dec 8, 2020
@ellert ellert deleted the better-fix branch December 8, 2020 19:18
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

Successfully merging this pull request may close these issues.

None yet

3 participants