From 6faddc3870b9dad0ed6d178492e92b03e8c00a8c Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Thu, 9 Feb 2023 11:23:11 -0800 Subject: [PATCH] Fix string key issue with constexpr StrKey in Performance C++ native module Summary: I encountered build error when using performance API in catalyst android mobile app. The error message P617433618 points at using non-const `std::strlen` API in a `constexpr`. ``` $ buck install catalyst-android ... stderr: xplat/js/react-native-github/Libraries/WebPerformance/PerformanceEntryReporter.cpp:208:13: error: constexpr constructor never produces a constant expression [-Winvalid-constexpr] constexpr StrKey(const char *s) ^ xplat/js/react-native-github/Libraries/WebPerformance/PerformanceEntryReporter.cpp:209:39: note: non-constexpr function 'strlen' cannot be used in a constant expression : key(folly::hash::fnv32_buf(s, std::strlen(s))) {} ``` Changelog: [General][Fixed] - Fixed string key calculation in constexpr from Performance C++ native module. Reviewed By: javache Differential Revision: D43136624 fbshipit-source-id: c691671b157b507745c67a505c91f75cf6b878d1 --- Libraries/WebPerformance/PerformanceEntryReporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/WebPerformance/PerformanceEntryReporter.cpp b/Libraries/WebPerformance/PerformanceEntryReporter.cpp index fc5bfa0c5a6dca..2cee8e6716944d 100644 --- a/Libraries/WebPerformance/PerformanceEntryReporter.cpp +++ b/Libraries/WebPerformance/PerformanceEntryReporter.cpp @@ -206,7 +206,7 @@ void PerformanceEntryReporter::scheduleFlushBuffer() { struct StrKey { uint32_t key; constexpr StrKey(const char *s) - : key(folly::hash::fnv32_buf(s, std::strlen(s))) {} + : key(folly::hash::fnv32_buf(s, sizeof(s) - 1)) {} constexpr bool operator==(const StrKey &rhs) const { return key == rhs.key;