Skip to content

Fix metaphone encode compiler warning #10788

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

Closed
wants to merge 1 commit into from

Conversation

iluuu1994
Copy link
Member

@iluuu1994 iluuu1994 commented Mar 5, 2023

warning: array subscript -65 is below array bounds of ‘const char[26]‘ [-Warray-bounds]

Errors like these sometimes only appear with optimizations when inlining/loop unrolling.

warning: array subscript -65 is below array bounds of ‘const char[26]‘
[-Warray-bounds]

Errors like these sometimes only appear with optimizations when inlining/look
unrolling.
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. It looks good. and adding an assert is definitely a good idea in any case :)

@@ -79,21 +79,28 @@ static const char _codes[26] =


/* Note: these macros require an uppercase letter input! */
#define ENCODE(c) (isalpha(c) ? _codes[((c) - 'A')] : 0)
Copy link
Member

Choose a reason for hiding this comment

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

I guess the comment saying "macros" is strictly speaking incorrect right now, since we have a function too.

static zend_always_inline char encode(char c) {
if (isalpha(c)) {
ZEND_ASSERT(c >= 'A' && c <= 'Z');
return _codes[((c) - 'A')];
Copy link
Member

Choose a reason for hiding this comment

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

Also slightly stupid codestyle nit: we don't need the parens here anymore, but I don't really care as it doesn't matter anyway...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, true 🙂👍

@iluuu1994 iluuu1994 closed this in 5904952 Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants