-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Use strlen(str) instead of sizeof(str)-1 for directly declared strings #8336
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
Conversation
3fcb9a2
to
9f8ccaf
Compare
Tip for this type of replacement: Use Coccinelle.
|
@TimWolla this PR aims to replace only the "directly declared strings" (like |
I'm a bit worried about merge conflicts when merging upstream. We never removed the |
@mvorisek Coccinelle 😃. The patch gets a little more complicated, though.
|
The arg info files are generated files, however the script generating them is not updated. |
Interestingly MSVC does not optimize |
Yeah, I think this is acceptable; a lot of other important optimizations are not done with |
form[l+sizeof("l")-2]=spec; | ||
form[l+sizeof("l")-1]='\0'; | ||
form[l+strlen("l")]='\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either keep the sizeof here, or I would imagine using strlen
for the line above, but this looks a bit weird and might be done for good reasons
if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { | ||
if (memcmp(cmd, "<:", strlen("<:")) == SUCCESS) { | ||
state->in_code = 1; | ||
return; | ||
} else { | ||
if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { | ||
if (memcmp(cmd, ":>", strlen(":>")) == SUCCESS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: but these usages of SUCCESS
should probably be removed in favour of using 0
explicitly.
This seems like making changes just for the sake of making changes, so closing it. |
I refactored code to the prefered variant which is more readable and shorter. Is it a bad practise? I was planning to add Coccinelle script so the prefered variant is asserted by CI, so even merging issues are easily fixable. Can this PR be reopened? |
@TimWolla do you think Coccinelle can be used to transform spaces indentation to tabs? https://github.com/php/php-src/blob/master/.github/actions/verify-generated-files/action.yml#L15 can then be used for diff output |
Modernize & unify code to the prefered variant [1]
regex replace used:
sizeof(\s*\(\s*"[^"\\]*"\s*\))\s*-\s*1(?!\w)
strlen$1
I firstly replaced all
*.h
and*.c
files and then carefully reviewed the rest files.[1] #8241 (comment)