[PATCH] gsm_utils.c: cleanup + do not use dynamic memory when decoding 7bit messages

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/baseband-devel@lists.osmocom.org/.

Nico Golde nico at ngolde.de
Tue Sep 18 12:29:40 UTC 2012


---
 src/gsm/gsm_utils.c |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index 3f3a73f..f51cf1b 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -2,7 +2,7 @@
  * (C) 2008 by Daniel Willmann <daniel at totalueberwachung.de>
  * (C) 2009 by Holger Hans Peter Freyther <zecke at selfish.org>
  * (C) 2009-2010 by Harald Welte <laforge at gnumonks.org>
- * (C) 2010 by Nico Golde <nico at ngolde.de>
+ * (C) 2010-2012 by Nico Golde <nico at ngolde.de>
  *
  * All Rights Reserved
  *
@@ -127,9 +127,8 @@ int gsm_7bit_decode_hdr(char *text, const uint8_t *user_data, uint8_t septet_l,
 {
 	int i = 0;
 	int shift = 0;
-
-	uint8_t *rtext = calloc(septet_l, sizeof(uint8_t));
-	uint8_t tmp;
+	uint8_t c;
+	uint8_t next_is_ext = 0;
 
 	/* skip the user data header */
 	if (ud_hdr_ind) {
@@ -141,29 +140,29 @@ int gsm_7bit_decode_hdr(char *text, const uint8_t *user_data, uint8_t septet_l,
 	}
 
 	for (i = 0; i < septet_l; i++) {
-		rtext[i] =
+		c =
 			((user_data[((i + shift) * 7 + 7) >> 3] <<
 			  (7 - (((i + shift) * 7 + 7) & 7))) |
 			 (user_data[((i + shift) * 7) >> 3] >>
 			  (((i + shift) * 7) & 7))) & 0x7f;
-	}
 
-	for (i = 0; i < septet_l; i++) {
-		/* this is an extension character */
-		if(rtext[i] == 0x1b && i + 1 < septet_l){
-			tmp = rtext[i+1];
-			*(text++) = gsm_7bit_alphabet[0x7f + tmp];
-			i++;
+		if(c == 0x1b && i + 1 < septet_l){
+			next_is_ext = 1;
 			continue;
 		}
 
-		*(text++) = gsm_septet_lookup(rtext[i]);
+		/* this is an extension character */
+		if(next_is_ext){
+			next_is_ext = 0;
+			*(text++) = gsm_7bit_alphabet[0x7f + c];
+		} else {
+			*(text++) = gsm_septet_lookup(c);
+		}
 	}
 
 	if (ud_hdr_ind)
 		i += shift;
 	*text = '\0';
-	free(rtext);
 
 	return i;
 }
-- 
1.7.10.4


--6TrnltStXW4iwmi0--




More information about the baseband-devel mailing list