summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNico Golde2010-07-20 15:43:58 +0200
committerHolger Hans Peter Freyther2010-07-20 20:43:58 +0200
commitc0ce9aa20d6ad6095c9a11d00bbd14d200a7ee4e (patch)
tree28c08d07d2690957acc604255a56e1dc1ddd65a5 /src
parentgsm_7bit_decode: Handle the case of the last charachter being an escape (diff)
downloadlibosmocore-c0ce9aa20d6ad6095c9a11d00bbd14d200a7ee4e.tar.gz
libosmocore-c0ce9aa20d6ad6095c9a11d00bbd14d200a7ee4e.tar.xz
libosmocore-c0ce9aa20d6ad6095c9a11d00bbd14d200a7ee4e.zip
tests: don't hardcode length values of expected encoding gsm_7bit_encode:
make sure to return the number of actually written bytes gsm_7bit_decode: calculate length of resulting septets from input length before decoding The input length to gsm_7bit_decode reflects the number of encoded bytes to be decoded. As the decoding is done on the input in septetes we need to take this into account and recalculate the length.
Diffstat (limited to 'src')
-rw-r--r--src/gsm_utils.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/gsm_utils.c b/src/gsm_utils.c
index 3a378ac..1a7ba0e 100644
--- a/src/gsm_utils.c
+++ b/src/gsm_utils.c
@@ -51,19 +51,21 @@ int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t length)
{
int i = 0;
int l = 0;
- uint8_t *rtext = calloc(length, sizeof(uint8_t));
+ int septet_l = (length * 8) / 7;
+ uint8_t *rtext = calloc(septet_l + 1, sizeof(uint8_t));
uint8_t tmp;
/* FIXME: We need to account for user data headers here */
i += l;
- for (; i < length; i ++){
+ for (; i < septet_l; i++){
rtext[i] =
((user_data[(i * 7 + 7) >> 3] <<
(7 - ((i * 7 + 7) & 7))) |
(user_data[(i * 7) >> 3] >>
((i * 7) & 7))) & 0x7f;
}
- for(i = 0; i < length; i++){
+
+ for(i = 0; i < septet_l; i++){
/* this is an extension character */
if(rtext[i] == 0x1b && i + 1 < length){
tmp = rtext[i+1];
@@ -139,7 +141,7 @@ int gsm_7bit_encode(uint8_t *result, const char *data)
}
free(rdata);
- return i;
+ return z;
}
/* determine power control level for given dBm value, as indicated