Change in libosmocore[master]: add osmo_escape_cstr and osmo_quote_cstr

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

neels gerrit-no-reply at lists.osmocom.org
Sun Nov 24 19:01:31 UTC 2019


Hello laforge, Jenkins Builder, 

I'd like you to reexamine a change. Please visit

    https://gerrit.osmocom.org/c/libosmocore/+/16160

to look at the new patch set (#4).

Change subject: add osmo_escape_cstr and osmo_quote_cstr
......................................................................

add osmo_escape_cstr and osmo_quote_cstr

Provide string escaping that
- returns the required buffer size, so it can be used with OSMO_STRBUF_APPEND().
- uses C compatible string constant escaping sequences.

This is intended as a replacement for all previous osmo_escape_str* and
osmo_quote_str* API. It pains me that I didn't get them right the first nor the
second time:
- The buffer functions do not return the chars needed, which is required for
  allocating sufficient memory in the *_c versions of the functions.
- Because of that, these functions are accurately usable for
  OSMO_STRBUF_APPEND(), producing truncated strings, for example when dumping a
  GSUP message.
- They do not use the C equivalent string constant escaping: for some reason I
  thought "\15" would be valid, but it should be "\x0f".
If I could, I would completely drop those mislead implementations ... but
backwards compat prohibits that.

A previous patch already provided internal static functions that accurately
return the required buffer size. Enhance these to also support C compatible
string escaping, and use them as implementation of the new functions:

osmo_escape_cstr_buf()
osmo_escape_cstr_c()
osmo_quote_cstr_buf()
osmo_quote_cstr_c()

In the tests for these, also test C string equivalence.

Naming: from API versions, it would be kind of logical to call them
osmo_escape_str_buf3() and osmo_escape_str_c2(). Since these anyway return a
different escaping, it makes sense to me to have distinct names instead.

Quasi missing are variants of the non-C-compatible weird legacy escaping that
return the required buffer size, but I refrain from adding those, because we
have enough API cruft as it is. Just always use these new cstr variants.

Change-Id: I3dfb892036e01000033dd8e7e4a6a0c32a3caa9b
---
M include/osmocom/core/utils.h
M src/utils.c
M tests/utils/utils_test.c
M tests/utils/utils_test.ok
4 files changed, 301 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/60/16160/4
-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16160
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I3dfb892036e01000033dd8e7e4a6a0c32a3caa9b
Gerrit-Change-Number: 16160
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: newpatchset
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191124/66f43b08/attachment.htm>


More information about the gerrit-log mailing list