Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jmagman
Copy link
Member

@jmagman jmagman commented Feb 8, 2022

Fix some of the clang-tidy errors in the macOS embedder found in #31291 (comment).

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman jmagman self-assigned this Feb 8, 2022
[engine setViewController:viewController];

// Unit test localization is unnecessary.
// NOLINTBEGIN(clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker)
Copy link
Member Author

Choose a reason for hiding this comment

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

error: User-facing text should use localized string macro [clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,-warnings-as-errors]

size_t len = strlen(event->character);
char* character = new char[len + 1];
strcpy(character, event->character);
strlcpy(character, event->character, sizeof(character));
Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't matter for this unit test, but can't hurt.

error: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors]

NSCAssert(keyLabelChar <= 0x10FFFF, @"Out of range keylabel 0x%x", keyLabelChar);
character = keyLabelChar;
}
delete[] keyLabel;
Copy link
Member Author

Choose a reason for hiding this comment

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

error: Potential leak of memory pointed to by 'keyLabel' [clang-analyzer-cplusplus.NewDeleteLeaks,-warnings-as-errors]

}

} // flutter::testing
} // namespace flutter::testing
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just a warning, but fix it anyway:

warning: namespace 'flutter::testing' ends with an unrecognized comment [google-readability-namespace-comments]

void EpsilonRandomSleep() {
TimeDelta duration =
TimeDelta::FromMilliseconds(static_cast<unsigned>(rand()) % 20u);
TimeDelta::FromMilliseconds(static_cast<unsigned>(arc4random()) % 20u);
Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't matter for these unit tests, but can't hurt.

error: Function 'rand' is obsolete because it implements a poor random number generator.  Use 'arc4random' instead [clang-analyzer-security.insecureAPI.rand,-warnings-as-errors]


#include "flutter/fml/synchronization/waitable_event.h"

#include <stdlib.h>
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, why isn't this include sufficient?

../../flutter/fml/synchronization/waitable_event_unittest.cc:35:57: error: use of undeclared identifier 'arc4random'
      TimeDelta::FromMilliseconds(static_cast<unsigned>(arc4random()) % 20u);

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8822761656441545457/+/u/build_host_debug_unopt/stdout

@jmagman
Copy link
Member Author

jmagman commented Feb 9, 2022

Closing in favor of Zach's fixes in #31291.

@jmagman jmagman closed this Feb 9, 2022
@jmagman jmagman deleted the mac-clang branch February 9, 2022 20:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant