diff --git a/Android.mk b/Android.mk index 4ef1d9382..2fddabfb9 100644 --- a/Android.mk +++ b/Android.mk @@ -227,7 +227,6 @@ LOCAL_SRC_FILES := \ src/core/utils/child_supervision.cpp \ src/core/utils/heap.cpp \ src/core/utils/jam_detector.cpp \ - src/core/utils/missing_strnlen.c \ src/core/utils/parse_cmdline.cpp \ src/core/utils/slaac_address.cpp \ src/ncp/hdlc.cpp \ diff --git a/BUILD.gn b/BUILD.gn index 1ead97666..a9dff17ae 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -159,7 +159,6 @@ static_library("lib-ot-core") { "src/core/utils/child_supervision.cpp", "src/core/utils/heap.cpp", "src/core/utils/jam_detector.cpp", - "src/core/utils/missing_strnlen.c", "src/core/utils/parse_cmdline.cpp", "src/core/utils/slaac_address.cpp", "src/ncp/hdlc.cpp", diff --git a/configure.ac b/configure.ac index aa14d1962..2a98a4129 100644 --- a/configure.ac +++ b/configure.ac @@ -170,10 +170,6 @@ if test "${enable_no_executables_hack}" = "yes" then AC_MSG_RESULT([yes]) AC_NO_EXECUTABLES - # Here we guess conservative values for tests that require link checks - # to test for these features. This will prevent these checks from - # being performed later in the configuration process. - ac_cv_func_strnlen=${ac_cv_func_strnlen-no} else AC_MSG_RESULT([no]) fi @@ -946,11 +942,6 @@ AC_HEADER_STDC AC_CHECK_HEADERS([stdint.h]) AC_CHECK_HEADERS([string.h]) -# -# Missing Functions -# -AC_CHECK_FUNC([strnlen], [AC_DEFINE([HAVE_STRNLEN], [1], [Define if strnlen exists.])]) - # # Check for types and structures # diff --git a/etc/cmake/checks.cmake b/etc/cmake/checks.cmake index 9e47bcd15..ab7bb88b8 100644 --- a/etc/cmake/checks.cmake +++ b/etc/cmake/checks.cmake @@ -26,8 +26,4 @@ # POSSIBILITY OF SUCH DAMAGE. # -include(CheckFunctionExists) - -check_function_exists("strnlen" HAVE_STRNLEN) - configure_file(${PROJECT_SOURCE_DIR}/etc/cmake/openthread-config-generic.h.in ${PROJECT_BINARY_DIR}/etc/cmake/openthread-config-generic.h) diff --git a/etc/cmake/openthread-config-generic.h.in b/etc/cmake/openthread-config-generic.h.in index 278b8192a..95c23b8b1 100644 --- a/etc/cmake/openthread-config-generic.h.in +++ b/etc/cmake/openthread-config-generic.h.in @@ -25,6 +25,3 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - -/* Define if strnlen exists. */ -#cmakedefine01 HAVE_STRNLEN diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 672cf3259..4d770161b 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -3611,7 +3611,7 @@ void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer) mServer = &aServer; - VerifyOrExit(aBuf != NULL && strnlen(aBuf, aBufLength + 1) <= aBufLength); + VerifyOrExit(aBuf != NULL && StringLength(aBuf, aBufLength + 1) <= aBufLength); VerifyOrExit(Utils::CmdLineParser::ParseCmd(aBuf, argc, argv, kMaxArgs) == OT_ERROR_NONE, mServer->OutputFormat("Error: too many args (max %d)\r\n", kMaxArgs)); diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c7b4e2444..99c58cdea 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -178,7 +178,6 @@ set(COMMON_SOURCES utils/child_supervision.cpp utils/heap.cpp utils/jam_detector.cpp - utils/missing_strnlen.c utils/parse_cmdline.cpp utils/slaac_address.cpp ) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index d49efb72b..81f0c9a2e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -235,7 +235,6 @@ SOURCES_COMMON = \ utils/child_supervision.cpp \ utils/heap.cpp \ utils/jam_detector.cpp \ - utils/missing_strnlen.c \ utils/parse_cmdline.cpp \ utils/slaac_address.cpp \ $(NULL) @@ -267,7 +266,6 @@ libopenthread_radio_a_SOURCES = \ radio/radio_callbacks.cpp \ radio/radio_platform.cpp \ thread/link_quality.cpp \ - utils/missing_strnlen.c \ utils/parse_cmdline.cpp \ $(NULL) diff --git a/src/core/common/string.cpp b/src/core/common/string.cpp index c57c70b98..f10e017a5 100644 --- a/src/core/common/string.cpp +++ b/src/core/common/string.cpp @@ -35,6 +35,18 @@ namespace ot { +uint16_t StringLength(const char *aString, uint16_t aMaxLength) +{ + uint16_t ret; + + for (ret = 0; (ret < aMaxLength) && (aString[ret] != 0); ret++) + { + // Empty loop. + } + + return ret; +} + otError StringBase::Write(char *aBuffer, uint16_t aSize, uint16_t &aLength, const char *aFormat, va_list aArgs) { otError error = OT_ERROR_NONE; diff --git a/src/core/common/string.hpp b/src/core/common/string.hpp index 99c587fa1..0db897f60 100644 --- a/src/core/common/string.hpp +++ b/src/core/common/string.hpp @@ -57,6 +57,17 @@ namespace ot { * */ +/** + * This function returns the number of characters that precede the terminating NULL character. + * + * @param[in] aString A pointer to the string. + * @param[in] aMaxLength The maximum length in bytes. + * + * @returns The number of characters that precede the terminating NULL character or @p aMaxLength, whichever is smaller. + * + */ +uint16_t StringLength(const char *aString, uint16_t aMaxLength); + /** * This class defines the base class for `String`. * diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index 06f90609c..b7f179876 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -495,7 +495,7 @@ void Diags::ProcessLine(const char *aString, char *aOutput, size_t aOutputMaxLen char * argVector[kMaxArgs]; uint8_t argCount = 0; - VerifyOrExit(strnlen(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = OT_ERROR_NO_BUFS); + VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = OT_ERROR_NO_BUFS); strcpy(buffer, aString); error = ot::Utils::CmdLineParser::ParseCmd(buffer, argCount, argVector, kMaxArgs); diff --git a/src/core/mac/mac_types.cpp b/src/core/mac/mac_types.cpp index a0b33a385..643a2cc41 100644 --- a/src/core/mac/mac_types.cpp +++ b/src/core/mac/mac_types.cpp @@ -123,7 +123,7 @@ uint8_t NetworkName::Data::CopyTo(char *aBuffer, uint8_t aMaxSize) const NetworkName::Data NetworkName::GetAsData(void) const { - uint8_t len = static_cast(strnlen(m8, kMaxSize + 1)); + uint8_t len = static_cast(StringLength(m8, kMaxSize + 1)); return Data(m8, len); } @@ -131,7 +131,7 @@ NetworkName::Data NetworkName::GetAsData(void) const otError NetworkName::Set(const Data &aNameData) { otError error = OT_ERROR_NONE; - uint8_t newLen = static_cast(strnlen(aNameData.GetBuffer(), aNameData.GetLength())); + uint8_t newLen = static_cast(StringLength(aNameData.GetBuffer(), aNameData.GetLength())); VerifyOrExit(newLen <= kMaxSize, error = OT_ERROR_INVALID_ARGS); diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index e5cd04842..46dc70887 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -254,7 +254,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64, const char *aPskd VerifyOrExit(mState == OT_COMMISSIONER_STATE_ACTIVE, error = OT_ERROR_INVALID_STATE); - VerifyOrExit(strnlen(aPskd, Dtls::kPskMaxLength + 1) <= Dtls::kPskMaxLength, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(StringLength(aPskd, Dtls::kPskMaxLength + 1) <= Dtls::kPskMaxLength, error = OT_ERROR_INVALID_ARGS); RemoveJoiner(aEui64, 0); // remove immediately @@ -387,7 +387,7 @@ otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl) ExitNow(); } - len = static_cast(strnlen(aProvisioningUrl, sizeof(mProvisioningUrl))); + len = static_cast(StringLength(aProvisioningUrl, sizeof(mProvisioningUrl))); VerifyOrExit(len < sizeof(mProvisioningUrl), error = OT_ERROR_INVALID_ARGS); @@ -953,7 +953,7 @@ void Commissioner::HandleJoinerFinalize(Coap::Message &aMessage, const Ip6::Mess if (Tlv::GetTlv(aMessage, Tlv::kProvisioningUrl, sizeof(provisioningUrl), provisioningUrl) == OT_ERROR_NONE) { - uint8_t len = static_cast(strnlen(mProvisioningUrl, sizeof(mProvisioningUrl))); + uint8_t len = static_cast(StringLength(mProvisioningUrl, sizeof(mProvisioningUrl))); if ((provisioningUrl.GetProvisioningUrlLength() != len) || !memcmp(provisioningUrl.GetProvisioningUrl(), mProvisioningUrl, len)) @@ -1110,8 +1110,8 @@ otError Commissioner::GeneratePskc(const char * aPassPhrase, uint16_t passphraseLen; uint8_t networkNameLen; - passphraseLen = static_cast(strnlen(aPassPhrase, OT_COMMISSIONING_PASSPHRASE_MAX_SIZE + 1)); - networkNameLen = static_cast(strnlen(aNetworkName, OT_NETWORK_NAME_MAX_SIZE + 1)); + passphraseLen = static_cast(StringLength(aPassPhrase, OT_COMMISSIONING_PASSPHRASE_MAX_SIZE + 1)); + networkNameLen = static_cast(StringLength(aNetworkName, OT_NETWORK_NAME_MAX_SIZE + 1)); VerifyOrExit((passphraseLen >= OT_COMMISSIONING_PASSPHRASE_MIN_SIZE) && (passphraseLen <= OT_COMMISSIONING_PASSPHRASE_MAX_SIZE) && diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 1955cb3f9..1e137e8ef 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -850,7 +850,7 @@ public: */ void SetCommissionerId(const char *aCommissionerId) { - size_t length = strnlen(aCommissionerId, sizeof(mCommissionerId)); + uint16_t length = StringLength(aCommissionerId, sizeof(mCommissionerId)); memcpy(mCommissionerId, aCommissionerId, length); SetLength(static_cast(length)); } @@ -1872,7 +1872,7 @@ public: */ void SetProvisioningUrl(const char *aProvisioningUrl) { - size_t len = aProvisioningUrl ? strnlen(aProvisioningUrl, kMaxLength) : 0; + uint16_t len = aProvisioningUrl ? StringLength(aProvisioningUrl, kMaxLength) : 0; SetLength(static_cast(len)); @@ -1931,7 +1931,7 @@ public: */ void SetVendorName(const char *aVendorName) { - size_t len = (aVendorName == NULL) ? 0 : strnlen(aVendorName, sizeof(mVendorName)); + uint16_t len = (aVendorName == NULL) ? 0 : StringLength(aVendorName, sizeof(mVendorName)); SetLength(static_cast(len)); @@ -1995,7 +1995,7 @@ public: */ void SetVendorModel(const char *aVendorModel) { - size_t len = (aVendorModel == NULL) ? 0 : strnlen(aVendorModel, sizeof(mVendorModel)); + uint16_t len = (aVendorModel == NULL) ? 0 : StringLength(aVendorModel, sizeof(mVendorModel)); SetLength(static_cast(len)); @@ -2059,7 +2059,7 @@ public: */ void SetVendorSwVersion(const char *aVendorSwVersion) { - size_t len = (aVendorSwVersion == NULL) ? 0 : strnlen(aVendorSwVersion, sizeof(mVendorSwVersion)); + uint16_t len = (aVendorSwVersion == NULL) ? 0 : StringLength(aVendorSwVersion, sizeof(mVendorSwVersion)); SetLength(static_cast(len)); @@ -2123,7 +2123,7 @@ public: */ void SetVendorData(const char *aVendorData) { - size_t len = (aVendorData == NULL) ? 0 : strnlen(aVendorData, sizeof(mVendorData)); + uint16_t len = (aVendorData == NULL) ? 0 : StringLength(aVendorData, sizeof(mVendorData)); SetLength(static_cast(len)); diff --git a/src/core/utils/missing_strnlen.c b/src/core/utils/missing_strnlen.c deleted file mode 100644 index 7245e14c5..000000000 --- a/src/core/utils/missing_strnlen.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "utils/wrap_string.h" - -size_t missing_strnlen(const char *s, size_t maxlen) -{ - size_t ret; - - for (ret = 0; (ret < maxlen) && (s[ret] != 0); ret++) - { - // Empty loop. - } - - return ret; -} diff --git a/src/core/utils/wrap_string.h b/src/core/utils/wrap_string.h index 057da272b..915b61822 100644 --- a/src/core/utils/wrap_string.h +++ b/src/core/utils/wrap_string.h @@ -49,17 +49,6 @@ /* Prototypes for our missing function replacements */ -/* See: https://www.freebsd.org/cgi/man.cgi?query=strnlen */ -WRAP_EXTERN_C size_t missing_strnlen(const char *s, size_t maxlen); - #undef WRAP_EXTERN_C -#ifndef HAVE_STRNLEN -#define HAVE_STRNLEN 0 -#endif - -#if (!HAVE_STRNLEN) -#define strnlen(S, N) missing_strnlen(S, N) -#endif - #endif // WRAP_STRING_H diff --git a/src/ncp/spinel.c b/src/ncp/spinel.c index 16e55ace6..a041c66af 100644 --- a/src/ncp/spinel.c +++ b/src/ncp/spinel.c @@ -147,6 +147,20 @@ static int spinel_errno_workaround_; #define require(c, l) require_action(c, l, {}) #endif +#ifndef strnlen +size_t strnlen(const char *s, size_t maxlen) +{ + size_t ret; + + for (ret = 0; (ret < maxlen) && (s[ret] != 0); ret++) + { + // Empty loop. + } + + return ret; +} +#endif + typedef struct { va_list obj; diff --git a/src/ncp/spinel_decoder.cpp b/src/ncp/spinel_decoder.cpp index d9af675ba..43f161839 100644 --- a/src/ncp/spinel_decoder.cpp +++ b/src/ncp/spinel_decoder.cpp @@ -35,7 +35,7 @@ #include "spinel_decoder.hpp" #include "common/code_utils.hpp" -#include "utils/wrap_string.h" +#include "common/string.hpp" namespace ot { namespace Ncp { @@ -299,7 +299,7 @@ otError SpinelDecoder::ReadUtf8(const char *&aUtf8) // Ensure there is at least one byte (for null character). VerifyOrExit(mIndex + sizeof(uint8_t) <= mEnd, error = OT_ERROR_PARSE); - len = strnlen(reinterpret_cast(&mFrame[mIndex]), mEnd - mIndex); + len = StringLength(reinterpret_cast(&mFrame[mIndex]), mEnd - mIndex); VerifyOrExit(len < static_cast(mEnd - mIndex), error = OT_ERROR_PARSE); aUtf8 = reinterpret_cast(&mFrame[mIndex]); diff --git a/src/posix/platform/radio_spinel.cpp b/src/posix/platform/radio_spinel.cpp index ba6168ed8..1ec7ca032 100644 --- a/src/posix/platform/radio_spinel.cpp +++ b/src/posix/platform/radio_spinel.cpp @@ -531,7 +531,7 @@ otError RadioSpinel::ThreadDatasetHandler(const uint8_t *aBuffer, uint16_t aLeng size_t len; SuccessOrExit(error = decoder.ReadUtf8(name)); - len = strnlen(name, OT_NETWORK_NAME_MAX_SIZE); + len = StringLength(name, OT_NETWORK_NAME_MAX_SIZE); memcpy(opDataset.mNetworkName.m8, name, len); opDataset.mNetworkName.m8[len] = '\0'; opDataset.mComponents.mIsNetworkNamePresent = true; diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index a33d2c7b7..2e1860598 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -122,7 +122,6 @@ check_PROGRAMS += \ test-priority-queue \ test-pskc \ test-string \ - test-strnlen \ test-timer \ $(NULL) @@ -221,9 +220,6 @@ test_pskc_SOURCES = $(COMMON_SOURCES) test_pskc.cpp test_string_LDADD = $(COMMON_LDADD) test_string_SOURCES = $(COMMON_SOURCES) test_string.cpp -test_strnlen_LDADD = $(COMMON_LDADD) -test_strnlen_SOURCES = test_strnlen.c - test_spinel_decoder_LDADD = $(COMMON_LDADD) test_spinel_decoder_SOURCES = $(COMMON_SOURCES) test_spinel_decoder.cpp @@ -259,7 +255,6 @@ PRETTY_FILES = \ $(test_spinel_decoder_SOURCES) \ $(test_spinel_encoder_SOURCES) \ $(test_string_SOURCES) \ - $(test_strnlen_SOURCES) \ $(test_timer_SOURCES) \ $(test_toolchain_SOURCES) \ $(NULL) diff --git a/tests/unit/test_string.cpp b/tests/unit/test_string.cpp index b7847887d..692819ac2 100644 --- a/tests/unit/test_string.cpp +++ b/tests/unit/test_string.cpp @@ -117,11 +117,34 @@ void TestString(void) printf(" -- PASS\n"); } +void TestStringLength(void) +{ + char string_a[5] = "\0foo"; + char string_b[8] = "foo\0bar"; + + printf("\nTest 4: String::StringLength() method\n"); + + VerifyOrQuit(StringLength(string_a, 0) == 0, "StringLength() 0len 0 fails"); + VerifyOrQuit(StringLength(string_a, 1) == 0, "StringLength() 0len 1 fails"); + VerifyOrQuit(StringLength(string_a, 2) == 0, "StringLength() 0len 2 fails"); + + VerifyOrQuit(StringLength(string_b, 0) == 0, "StringLength() 3len 0 fails"); + VerifyOrQuit(StringLength(string_b, 1) == 1, "StringLength() 3len 1 fails"); + VerifyOrQuit(StringLength(string_b, 2) == 2, "StringLength() 3len 2 fails"); + VerifyOrQuit(StringLength(string_b, 3) == 3, "StringLength() 3len 3 fails"); + VerifyOrQuit(StringLength(string_b, 4) == 3, "StringLength() 3len 4 fails"); + VerifyOrQuit(StringLength(string_b, 5) == 3, "StringLength() 3len 5 fails"); + VerifyOrQuit(StringLength(string_b, 6) == 3, "StringLength() 3len 6 fails"); + + printf(" -- PASS\n"); +} + } // namespace ot int main(void) { ot::TestString(); + ot::TestStringLength(); printf("\nAll tests passed.\n"); return 0; } diff --git a/tests/unit/test_strnlen.c b/tests/unit/test_strnlen.c deleted file mode 100644 index 73be627a9..000000000 --- a/tests/unit/test_strnlen.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2016-2017, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include -#include "utils/wrap_string.h" - -static void fail(const char *msg) -{ - fprintf(stderr, "%s\n", msg); - exit(EXIT_FAILURE); -} - -int main(int argc, char **argv) -{ - char string_a[5] = "\0foo"; - char string_b[8] = "foo\0bar"; - - (void)argc; - (void)argv; - - if (0 != missing_strnlen(string_a, 0)) - { - fail("0len 0 fails"); - } - - if (0 != missing_strnlen(string_a, 1)) - { - fail("0len 1 fails"); - } - - if (0 != missing_strnlen(string_a, 2)) - { - fail("0len 2 fails"); - } - - if (0 != missing_strnlen(string_b, 0)) - { - fail("3len 0 fails"); - } - - if (1 != missing_strnlen(string_b, 1)) - { - fail("3len 1 fails"); - } - - if (2 != missing_strnlen(string_b, 2)) - { - fail("3len 2 fails"); - } - - if (3 != missing_strnlen(string_b, 3)) - { - fail("3len 3 fails"); - } - - if (3 != missing_strnlen(string_b, 4)) - { - fail("3len 4 fails"); - } - - if (3 != missing_strnlen(string_b, 5)) - { - fail("3len 5 fails"); - } - - if (3 != missing_strnlen(string_b, 6)) - { - fail("3len 6 fails"); - } - - printf("OK\n"); - return EXIT_SUCCESS; -}