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

Fix macro invocation with post-increment index as argument #1125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

NDMDevel
Copy link

@NDMDevel NDMDevel commented Mar 3, 2022

In WebRequest.cpp at line 150:
while (i<len && __is_param_char(((char*)buf)[i++]));
the macro __is_param_char will expand producing multiple i++ invocations making the algorithm to (sometimes) fail.

In WebRequest.cpp at line 150:
while (i<len && __is_param_char(((char*)buf)[i++]));
the macro __is_param_char will expand producing multiple i++ invocations making the algorithm to (sometimes) fail.
Small bug fix at WebRequest.cpp
Copy link

@mrengineer7777 mrengineer7777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree: this looks like a bug. "__is_param_char" macro expansion will cause multiple increments of i++. That is a dangerous macro. Rather than a macro, perhaps we should be using a function here?

bool is_param_char(char c) {
  return 
	(c != 0) && 
	(c != '{') && 
	(c != '[') && 
	(c != '&') && 
	(c != '=');
}

From reading your code, it should also work around the bug, but I can't test it.
Edit: explicitly test c for null (c!=0) instead of (c).

@NDMDevel
Copy link
Author

NDMDevel commented Mar 9, 2022

Yes, I also think is best to replace the macro with a function.
I'll test your function in my code, although is certain that will produce the same result as the macro.
Thanks

@NDMDevel NDMDevel closed this Mar 9, 2022
@NDMDevel NDMDevel reopened this Mar 9, 2022
Copy link

@mrengineer7777 mrengineer7777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@mrengineer7777
Copy link

@me-no-dev Please review.

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.

2 participants