Skip to content

Commit

Permalink
[TextFields] Fix character count overflow. (#7255)
Browse files Browse the repository at this point in the history
Fixes possible overflow when reading out the character count remaining value.

Found while testing #7157
  • Loading branch information
Robert Moore authored and codeman7 committed Apr 23, 2019
1 parent 7b9e9d3 commit 63044ff
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions components/TextFields/src/MDCTextInputControllerBase.m
Expand Up @@ -1486,13 +1486,16 @@ - (void)textInputDidChange:(NSNotification *)note {

// Accessibility
if (self.textInput.isEditing && self.characterCountMax > 0) {
NSUInteger charactersForTextInput =
[self.characterCounter characterCountForTextInput:self.textInput];
NSString *announcementString;
if (!announcementString.length) {
announcementString = [NSString
stringWithFormat:@"%lu characters remaining",
(unsigned long)(self.characterCountMax -
[self.characterCounter
characterCountForTextInput:self.textInput])];
announcementString =
[NSString stringWithFormat:@"%lu characters remaining",
charactersForTextInput > self.characterCountMax
? 0U
: (unsigned long)(MAX(0, self.characterCountMax -
charactersForTextInput))];
}

// Simply sending a layout change notification does not seem to
Expand Down

0 comments on commit 63044ff

Please sign in to comment.