Change in libosmocore[master]: gsm48_decode_bcd_number2(): allow avoiding deprecation

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 Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Apr 30 00:54:56 UTC 2019


Neels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/13816


Change subject: gsm48_decode_bcd_number2(): allow avoiding deprecation
......................................................................

gsm48_decode_bcd_number2(): allow avoiding deprecation

gsm48_decode_bcd_number() is marked as deprecated, so
gsm48_decode_bcd_number2() will cause deprecation warnings as long as it calls
gsm48_decode_bcd_number(). Hence move the code to gsm48_decode_bcd_number2().

Change-Id: I81925e9afb3451de9b8a268d482f79ee20ca14d6
---
M src/gsm/gsm48_ie.c
1 file changed, 29 insertions(+), 27 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/13816/1

diff --git a/src/gsm/gsm48_ie.c b/src/gsm/gsm48_ie.c
index 0e5f253..ca6489a 100644
--- a/src/gsm/gsm48_ie.c
+++ b/src/gsm/gsm48_ie.c
@@ -55,7 +55,36 @@
 			    const uint8_t *bcd_lv, int h_len)
 {
 	uint8_t in_len = bcd_lv[0];
+	/* Just assume the input buffer is big enough for the length byte and the following data, so pass in_len + 1 for
+	 * the input buffer size. */
+	return gsm48_decode_bcd_number2(output, output_len, bcd_lv, in_len + 1, h_len);
+}
+
+/*! Decode a 'called/calling/connect party BCD number' as in 10.5.4.7.
+ * \param[out] output  Caller-provided output buffer.
+ * \param[in] output_len  sizeof(output).
+ * \param[in] bcd_lv  Length-Value part of to-be-decoded IE.
+ * \param[in] input_len  Size of the bcd_lv buffer for bounds checking.
+ * \param[in] h_len  Length of an optional header between L and V parts.
+ * \return 0 in case of success, negative on error. Errors checked: no or too little input data, no or too little
+ * output buffer size, IE length exceeds input data size, decoded number exceeds size of the output buffer. The output
+ * is guaranteed to be nul terminated iff output_len > 0.
+ */
+int gsm48_decode_bcd_number2(char *output, size_t output_len,
+			     const uint8_t *bcd_lv, size_t input_len,
+			     size_t h_len)
+{
+	uint8_t in_len;
 	int i;
+	if (output_len < 1)
+		return -ENOSPC;
+	*output = '\0';
+	if (input_len < 1)
+		return -EIO;
+	in_len = bcd_lv[0];
+	/* len + 1: the BCD length plus the length byte itself must fit in the input buffer. */
+	if (input_len < in_len + 1)
+		return -EIO;
 
 	for (i = 1 + h_len; i <= in_len; i++) {
 		/* lower nibble */
@@ -76,33 +105,6 @@
 	return 0;
 }
 
-/*! Decode a 'called/calling/connect party BCD number' as in 10.5.4.7.
- * \param[out] output  Caller-provided output buffer.
- * \param[in] output_len  sizeof(output).
- * \param[in] bcd_lv  Length-Value part of to-be-decoded IE.
- * \param[in] input_len  Size of the bcd_lv buffer for bounds checking.
- * \param[in] h_len  Length of an optional header between L and V parts.
- * \return 0 in case of success, negative on error. Errors checked: no or too little input data, no or too little
- * output buffer size, IE length exceeds input data size, decoded number exceeds size of the output buffer. The output
- * is guaranteed to be nul terminated iff output_len > 0.
- */
-int gsm48_decode_bcd_number2(char *output, size_t output_len,
-			     const uint8_t *bcd_lv, size_t input_len,
-			     size_t h_len)
-{
-	uint8_t len;
-	if (output_len < 1)
-		return -ENOSPC;
-	*output = '\0';
-	if (input_len < 1)
-		return -EIO;
-	len = bcd_lv[0];
-	/* len + 1: the BCD length plus the length byte itself must fit in the input buffer. */
-	if (input_len < len + 1)
-		return -EIO;
-	return gsm48_decode_bcd_number(output, output_len, bcd_lv, h_len);
-}
-
 /*! convert a single ASCII character to call-control BCD */
 static int asc_to_bcd(const char asc)
 {

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I81925e9afb3451de9b8a268d482f79ee20ca14d6
Gerrit-Change-Number: 13816
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190430/6043a619/attachment.htm>


More information about the gerrit-log mailing list