Change in libosmocore[master]: add osmo_{escape, quote}_str_buf2() for OSMO_STRBUF_APPEND() use

Neels Hofmeyr gerrit-no-reply at
Thu Apr 11 04:07:28 UTC 2019

Neels Hofmeyr has posted comments on this change. ( )

Change subject: add osmo_{escape,quote}_str_buf2() for OSMO_STRBUF_APPEND() use

Patch Set 1:

> So, this patch should probably not bother to introduce _buf functions that adhere to the snprintf() signature. It is fine to return a char* and use those with OSMO_STRBUF_PRINTF().

I remember now why i wanted a function that is directly usable for OSMO_STRBUF_APPEND(): it allows using the target buffer directly.

If I use OSMO_STRBUF_PRINTF(sb, "%s", osmo_escape_str_buf(buf2, ...)),
then I need to define a *second* buffer, and even if the final target buffer is large enough, if the intermediate buffer is too small, that part of the string will be truncated.

If instead I can use

  OSMO_STRBUF_APPEND(sb, osmo_escape_str_buf2, str, in_len);

then there is only one buffer involved, and that is the final target buffer that was probably passed in by the user.

So, having a signature returning char* is useful as direct printf() arg,
but also having a signature that returns int is useful for using the same buffer with OSMO_STRBUF_APPEND().

options that come to mind:

- add another signature kind that behaves like snprintf(), not *_buf but something named like snprintf(), which works with OSMO_STRBUF_APPEND() directly. maybe osmo_foo_name_snf()

- add another OSMO_STRBUF_xxx() macro that feeds the same sb buffer to *_buf() like signatures. That would have to do a strlen() to figure out how much of the buffer is left afterwards, but it would save the need for a lot of yet more str writing functions.

Going for the latter.

To view, visit
To unsubscribe, or for help writing mail filters, visit

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Id748b906b0083b1f1887f2be7a53cae705a8a9ae
Gerrit-Change-Number: 13573
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at>
Gerrit-CC: Harald Welte <laforge at>
Gerrit-Comment-Date: Thu, 11 Apr 2019 04:07:28 +0000
Gerrit-HasComments: No
Gerrit-HasLabels: No
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gerrit-log mailing list