Skip to content

Fix more C warnings #1159

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

Merged
merged 1 commit into from
Oct 16, 2017
Merged

Fix more C warnings #1159

merged 1 commit into from
Oct 16, 2017

Conversation

spevans
Copy link
Contributor

@spevans spevans commented Aug 4, 2017

  • Merge function prototypes with the declaration that follows
    on the next line to simplify declaration when the arguments
    differ due to preprocessor arguments.

  • Fix use of comma in while statement.

This is the second PR of C fixes along with #1157 after which the Xcode project can be updated to recommended settings to include the latest Clang warnings.

The while statement definitely needs checking, I went with && instead of || but a 2nd opinion would be good.

- Merge function prototypes with the declaration that follows
  on the next line to simplify declaration when the arguments
  differ due to preprocessor arguments.

- Fix use of comma in while statement.
@ianpartridge ianpartridge requested a review from parkera August 9, 2017 09:12
@ianpartridge
Copy link
Contributor

@swift-ci please test

1 similar comment
@ianpartridge
Copy link
Contributor

@swift-ci please test

@parkera
Copy link
Contributor

parkera commented Aug 10, 2017

We're in the process of a giant merge of CF stuff right now, so let's hold off on this for a bit.

@@ -3233,7 +3233,7 @@ Boolean CFStringFindWithOptionsAndLocale(CFStringRef string, CFStringRef stringT

do {
str1Char = CFStringGetCharacterFromInlineBuffer(&inlineBuf1, --index);
} while (CFUniCharIsMemberOfBitmap(str1Char, graphemeBMP), (rangeToSearch.location < index));
} while (CFUniCharIsMemberOfBitmap(str1Char, graphemeBMP) && (rangeToSearch.location < index));
Copy link
Contributor

Choose a reason for hiding this comment

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

oof! how was the previous even valid C?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to look it up! The first call is always executed then the result of the function after the , is evaluated for the while loop. I assume && is the correct operator here.

Copy link
Contributor

Choose a reason for hiding this comment

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

doing some testing here; this is actually a bug btw... the first function is called but the result is discarded, if you mark the CFUniCharIsMemberOfBitmap as __attribute__((pure)) or better yet __attribute__((const)) (which it is most appropriately delineated as) it ends up emitting a warning that the result is not used.

As Tony mentioned we are in the process of merging a bunch of CF things - I will keep an eye on this particular portion; file a bug on the owner and get back to you on this. We should probably fix it somehow but I need to validate exactly the right fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

@spevans / @phausler I think the original code is correct. The comma operator in C evaluates the first expression, discards the result and then evaluates the second and the overall expression evaluates to that (the value of the second expr).

Copy link
Contributor

@weissi weissi Aug 23, 2017

Choose a reason for hiding this comment

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

oh, sorry, think I'm wrong. If CFUniCharIsMemberOfBitmap(str1Char, graphemeBMP) doesn't have any side-effects, the original code looks wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI All I did in Xcode9 was 'Update to recommended settings' which enabled the latest clang warnings so I was just fixing those up.

@alblue
Copy link
Contributor

alblue commented Oct 5, 2017

@parkera the merging has happened now, can @spevans rebase and try this again?

@spevans
Copy link
Contributor Author

spevans commented Oct 5, 2017

@alblue I don't think the merge has happened yet, I thought it was going to be the public bits of 10.13 but I don't see anything in the commit log.

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

I vote we merge these changes today - they're just minor cleanups. @parkera @phausler any objections?

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit 82b286a into swiftlang:master Oct 16, 2017
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.

7 participants