[ocsp] Fix static string length calculation 20/214620/1
authorKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 24 Sep 2019 12:40:58 +0000 (14:40 +0200)
committerKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 24 Sep 2019 15:22:31 +0000 (17:22 +0200)
Change-Id: I13d6c6f825a9340bfd54462d7d6c9cbd46008dd2

src/manager/service/ocsp.cpp

index 60cdb5b..c6cb2fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 - 2019 Samsung Electronics Co.
+ *  Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 namespace CKM {
 
 namespace {
-const char *const HTTP_PREFIX = "http://";
-const size_t HTTP_PREFIX_LEN = sizeof(HTTP_PREFIX) / sizeof(HTTP_PREFIX[0]);
-const char *const HTTPS_PREFIX = "https://";
-const size_t HTTPS_PREFIX_LEN = sizeof(HTTPS_PREFIX) / sizeof(HTTPS_PREFIX[0]);
+template <size_t S>
+constexpr size_t staticStringLen(const char (&)[S]) {
+       static_assert(S, "static string of zero size");
+       return S-1;
+}
+
+const char HTTP_PREFIX[] = "http://";
+const size_t HTTP_PREFIX_LEN = staticStringLen(HTTP_PREFIX);
+const char HTTPS_PREFIX[] = "https://";
+const size_t HTTPS_PREFIX_LEN = staticStringLen(HTTPS_PREFIX);
 
 typedef std::unique_ptr<BIO, std::function<void(BIO *)>> BioUniquePtr;