Change in libosmocore[master]: fix osmo_quote_str_c() to alloc sufficient size

2019-11-24 Thread neels
neels has abandoned this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/16029 )

Change subject: fix osmo_quote_str_c() to alloc sufficient size
..


Abandoned

instead merged as I16c08eced41bf1b7acf6e95f658068ace99ca4c8
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16029
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I04d97e8eec93ffb74006503c356a68cceaf429ac
Gerrit-Change-Number: 16029
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-CC: osmith 
Gerrit-MessageType: abandon


Change in libosmocore[master]: fix osmo_quote_str_c() to alloc sufficient size

2019-11-18 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/16029 )

Change subject: fix osmo_quote_str_c() to alloc sufficient size
..


Patch Set 4: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16029
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I04d97e8eec93ffb74006503c356a68cceaf429ac
Gerrit-Change-Number: 16029
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-CC: osmith 
Gerrit-Comment-Date: Tue, 19 Nov 2019 00:57:28 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: fix osmo_quote_str_c() to alloc sufficient size

2019-11-12 Thread osmith
osmith has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/16029 )

Change subject: fix osmo_quote_str_c() to alloc sufficient size
..


Patch Set 4:

(1 comment)

https://gerrit.osmocom.org/c/libosmocore/+/16029/4/src/utils.c
File src/utils.c:

https://gerrit.osmocom.org/c/libosmocore/+/16029/4/src/utils.c@775
PS4, Line 775: The function signature is suitable for 
OSMO_STRBUF_APPEND_NOLEN().
This seems to be wrong, the description of OSMO_STRBUF_APPEND_NOLEN is:
> Like OSMO_STRBUF_APPEND(), but for function signatures that return the char* 
> buffer instead of a length.

But this function does return the length.



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16029
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I04d97e8eec93ffb74006503c356a68cceaf429ac
Gerrit-Change-Number: 16029
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: neels 
Gerrit-CC: osmith 
Gerrit-Comment-Date: Tue, 12 Nov 2019 08:50:29 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


Change in libosmocore[master]: fix osmo_quote_str_c() to alloc sufficient size

2019-11-11 Thread neels
neels has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/16029 )

Change subject: fix osmo_quote_str_c() to alloc sufficient size
..


Patch Set 4:

(1 comment)

osmo_quote_str* functions would make for an interesting anecdotal review of 
various ways of composing strings that we (I?) thought were great but later 
needed improving upon.

https://gerrit.osmocom.org/c/libosmocore/+/16029/4/src/utils.c
File src/utils.c:

https://gerrit.osmocom.org/c/libosmocore/+/16029/4/src/utils.c@780 
PS4, Line 780:  * \return Number of characters that would be written if bufsize 
were large enough excluding '\0' (like snprintf()).
interestingly enough, the \return doc didn't need any change, it was plain 
wrong for osmo_quote_str_buf2() :/



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16029
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I04d97e8eec93ffb74006503c356a68cceaf429ac
Gerrit-Change-Number: 16029
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: neels 
Gerrit-Comment-Date: Mon, 11 Nov 2019 20:25:40 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


Change in libosmocore[master]: fix osmo_quote_str_c() to alloc sufficient size

2019-11-11 Thread neels
neels has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/16029 )


Change subject: fix osmo_quote_str_c() to alloc sufficient size
..

fix osmo_quote_str_c() to alloc sufficient size

osmo_quote_str_c() allocates too small buffers when the quoted string also
contains unprintable characters that need escaping (which of course are longer
than strlen() + 3 that it currently naively assumes).

Add osmo_quote_str_buf3() to actually return the required buffer size
(sb.chars_needed), osmo_quote_str_buf2() unfortunately returns the char buffer
itself.

Hence implement osmo_quote_str_c() using OSMO_NAME_C_IMPL(), which now always
allocates sufficient size.

Change-Id: I04d97e8eec93ffb74006503c356a68cceaf429ac
---
M include/osmocom/core/utils.h
M src/utils.c
2 files changed, 18 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/29/16029/1

diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h
index ef58eeb..cb69b64 100644
--- a/include/osmocom/core/utils.h
+++ b/include/osmocom/core/utils.h
@@ -151,6 +151,7 @@
 char *osmo_escape_str_c(const void *ctx, const char *str, int in_len);
 const char *osmo_quote_str(const char *str, int in_len);
 char *osmo_quote_str_buf2(char *buf, size_t bufsize, const char *str, int 
in_len);
+size_t osmo_quote_str_buf3(char *buf, size_t bufsize, const char *str, int 
in_len);
 const char *osmo_quote_str_buf(const char *str, int in_len, char *buf, size_t 
bufsize);
 char *osmo_quote_str_c(const void *ctx, const char *str, int in_len);

diff --git a/src/utils.c b/src/utils.c
index ea1de0f..95245f5 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -756,6 +756,20 @@
return osmo_escape_str_buf2(buf, in_len+1, str, in_len);
 }

+/*! Like osmo_quote_str_buf3(), but returning the buf instead of the required 
number of characters.
+ * The function signature is suitable for OSMO_STRBUF_APPEND_NOLEN().
+ * \param[out] buf  string buffer to write escaped characters to.
+ * \param[in] bufsize  sizeof(buf).
+ * \param[in] str  A string that may contain any characters.
+ * \param[in] in_len  Pass -1 to print until nul char, or >= 0 to force a 
length.
+ * \return buf.
+ */
+char *osmo_quote_str_buf2(char *buf, size_t bufsize, const char *str, int 
in_len)
+{
+   osmo_quote_str_buf3(buf, bufsize, str, in_len);
+   return buf;
+}
+
 /*! Like osmo_escape_str_buf2(), but returns double-quotes around a string, or 
"NULL" for a NULL string.
  * This allows passing any char* value and get its C representation as string.
  * The function signature is suitable for OSMO_STRBUF_APPEND_NOLEN().
@@ -765,7 +779,7 @@
  * \param[in] in_len  Pass -1 to print until nul char, or >= 0 to force a 
length.
  * \return Number of characters that would be written if bufsize were large 
enough excluding '\0' (like snprintf()).
  */
-char *osmo_quote_str_buf2(char *buf, size_t bufsize, const char *str, int 
in_len)
+size_t osmo_quote_str_buf3(char *buf, size_t bufsize, const char *str, int 
in_len)
 {
struct osmo_strbuf sb = { .buf = buf, .len = bufsize };
if (!str)
@@ -775,7 +789,7 @@
OSMO_STRBUF_APPEND_NOLEN(sb, osmo_escape_str_buf2, str, in_len);
OSMO_STRBUF_PRINTF(sb, "\"");
}
-   return buf;
+   return sb.chars_needed;
 }

 /*! Like osmo_quote_str_buf2, but with unusual ordering of arguments, and may 
sometimes return string constants instead
@@ -815,21 +829,7 @@
  */
 char *osmo_quote_str_c(const void *ctx, const char *str, int in_len)
 {
-   size_t len = in_len == -1 ? strlen(str) : in_len;
-   char *buf;
-
-   /* account for two quote characters + terminating NUL */
-   len += 3;
-
-   /* some minimum length for things like "NULL" or "(error)" */
-   if (len < 32)
-   len = 32;
-
-   buf = talloc_size(ctx, len);
-   if (!buf)
-   return NULL;
-
-   return osmo_quote_str_buf2(buf, len, str, in_len);
+   OSMO_NAME_C_IMPL(ctx, 32, "(error)", osmo_quote_str_buf3, str, in_len)
 }

 /*! perform an integer square root operation on unsigned 32bit integer.

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16029
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I04d97e8eec93ffb74006503c356a68cceaf429ac
Gerrit-Change-Number: 16029
Gerrit-PatchSet: 1
Gerrit-Owner: neels 
Gerrit-MessageType: newchange