From 98ed3393cdfdf35ad0bb79f454474f2b27bf3d56 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 28 Mar 2019 13:26:53 +0100 Subject: osmo_escape_str_buf: Always copy, don't return input string pointer osmo_escape_str_buf() used to have the somewhat odd semantics that if no escaping was needed, it would return the original pointer without making any copy to the output buffer. While this seems like an elegant optimization, it is a very strange behavior and it works differently than all of our other *_buf() functions. Let's unify the API and turn osmo_escape_str_buf() into a strlcpy() if no escaping is needed. Change-Id: I3a02bdb27008a73101c2db41ac04248960ed4064 --- tests/utils/utils_test.c | 10 +--------- tests/utils/utils_test.ok | 2 -- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'tests/utils') diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c index d592fe04..711d6e12 100644 --- a/tests/utils/utils_test.c +++ b/tests/utils/utils_test.c @@ -545,7 +545,7 @@ static void str_escape_test(void) printf("- passthru:\n"); res = osmo_escape_str(printable, -1); - if (res != printable) + if (strcmp(res, printable)) printf("NOT passed through! \"%s\"\n", res); else printf("passed through unchanged \"%s\"\n", res); @@ -560,14 +560,6 @@ static void str_escape_test(void) memset(out_buf, 0x7f, sizeof(out_buf)); printf("\"%s\"\n", osmo_escape_str_buf((const char *)in_buf, sizeof(in_buf), out_buf, 10)); OSMO_ASSERT(out_buf[10] == 0x7f); - - printf("- passthrough without truncation when no escaping needed:\n"); - memset(in_buf, 'x', sizeof(in_buf)); - in_buf[19] = 'E'; - in_buf[20] = '\0'; - memset(out_buf, 0x7f, sizeof(out_buf)); - printf("\"%s\"\n", osmo_escape_str_buf((const char *)in_buf, -1, out_buf, 10)); - OSMO_ASSERT(out_buf[0] == 0x7f); } static void str_quote_test(void) diff --git a/tests/utils/utils_test.ok b/tests/utils/utils_test.ok index 1215ddd1..8fce9f13 100644 --- a/tests/utils/utils_test.ok +++ b/tests/utils/utils_test.ok @@ -232,8 +232,6 @@ passed through unchanged "printable" "" - truncation when too long: "\axxxxxxE" -- passthrough without truncation when no escaping needed: -"xxxxxxxxxxxxxxxxxxxE" Testing string quoting - all chars from 0 to 255 in batches of 16: -- cgit v1.2.3