Only Windows has strnlen_s.
authorElliott Hughes <enh@google.com>
Sat, 8 Oct 2016 18:13:40 +0000 (11:13 -0700)
committerElliott Hughes <enh@google.com>
Sat, 8 Oct 2016 18:13:40 +0000 (11:13 -0700)
The right way to ask for and check for strnlen_s on non-Windows would be:

  As with all bounds-checked functions, strnlen_s is only guaranteed to be
  available if __STDC_LIB_EXT1__ is defined by the implementation and if
  the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before
  including string.h.
    http://en.cppreference.com/w/c/string/byte/strlen

...but only Windows has any of this stuff. Android, Linux, and Mac OS all
don't. They do all have the POSIX 2008 strnlen(3), which is the same function
with a different name, but an earlier change deliberately replaced a call to
strnlen(3) with the current hand-written unoptimized implementation.

Bug: http://b/32019064
Test: builds
Change-Id: I4b5516b6438fe8ef3425c54d2bcddbdbb09b1814

framework/delibs/debase/deString.c

index 96ca7b4..7da424f 100644 (file)
@@ -177,7 +177,7 @@ char* deStrcat (char* s1, size_t size, const char* s2)
 
 size_t deStrnlen (const char* string, size_t maxSize)
 {
-#if ((DE_COMPILER == DE_COMPILER_MSC) && (DE_OS != DE_OS_WINCE)) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201100L))
+#if ((DE_COMPILER == DE_COMPILER_MSC) && (DE_OS != DE_OS_WINCE))
        return strnlen_s(string, maxSize);
 #else
        size_t len = 0;