From 32599fd50c32c1c0dbc44625725304cf3e5ab634 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Wed, 25 Jan 2017 11:15:52 -0800 Subject: [PATCH] Replace strlen("foo") with sizeof("foo") - 1. We have an upcoming change to Bionic that no longer allows us to treat strlen("foo") as a constant expression, which causes this bit of code to no longer compile. So, we need to either use __builtin_strlen("foo") or sizeof("foo") - 1 instead. (Note that the *optimizer* can still turn it into a constant, but optimization happens after we figure out if something is actually a constant expression or not.) sizeof("foo") is used elsewhere in this file, so I just went with that. Bug: 32073964 Test: Now builds. Change-Id: I2797ee75fd114e237de8e97c50549763c88f73f4 --- tests/cts/net/jni/NativeMultinetworkJni.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cts/net/jni/NativeMultinetworkJni.c b/tests/cts/net/jni/NativeMultinetworkJni.c index 6990efa452..91565043ec 100644 --- a/tests/cts/net/jni/NativeMultinetworkJni.c +++ b/tests/cts/net/jni/NativeMultinetworkJni.c @@ -88,7 +88,9 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runSetsocknetwork( return rval == 0 ? 0 : -saved_errno; } -static const int kSockaddrStrLen = INET6_ADDRSTRLEN + strlen("[]:65535"); +// Use sizeof("x") - 1 because we need a compile-time constant, and strlen("x") +// isn't guaranteed to fold to a constant. +static const int kSockaddrStrLen = INET6_ADDRSTRLEN + sizeof("[]:65535") - 1; void sockaddr_ntop(const struct sockaddr *sa, socklen_t salen, char *dst, const size_t size) { char addrstr[INET6_ADDRSTRLEN];