aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-03-28 18:07:17 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-03-28 18:59:04 +0200
commitcf4a5735e696c333b525425541a76faff2b01bd2 (patch)
treeb2aec3a378b923bc0d622c908ac5704286c3f425 /src
parenta8eafef966bfbd8046ee8319b889b2dee8391434 (diff)
range_enc_arfcns: avoid runtime error on zero size
If size <= 1, avoid allocating arfcns_left[size / 2], which results in a zero size and causes, with gcc 7.3.0 sanitizer, runtime errors: ../../../../src/osmo-bsc/src/libbsc/arfcn_range_encode.c:95:6: runtime error: variable length array bound evaluates to non-positive value 0 ../../../../src/osmo-bsc/src/libbsc/arfcn_range_encode.c:96:6: runtime error: variable length array bound evaluates to non-positive value 0 This fixes some of the errors of gsm0408_test, as revealed by a sanitizer build using gcc (Debian 7.3.0-12) 7.3.0. Change-Id: Idab2a194fb9d7c41ed3367f935080eaae4ce367f
Diffstat (limited to 'src')
-rw-r--r--src/libbsc/arfcn_range_encode.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/libbsc/arfcn_range_encode.c b/src/libbsc/arfcn_range_encode.c
index ae99fd912..84f9f635f 100644
--- a/src/libbsc/arfcn_range_encode.c
+++ b/src/libbsc/arfcn_range_encode.c
@@ -74,14 +74,8 @@ int range_enc_find_index(enum gsm48_range range, const int *freqs, const int siz
return -1;
}
-/**
- * Range encode the ARFCN list.
- * \param range The range to use.
- * \param arfcns The list of ARFCNs
- * \param size The size of the list of ARFCNs
- * \param out Place to store the W(i) output.
- */
-int range_enc_arfcns(enum gsm48_range range,
+/* Worker for range_enc_arfcns(), do not call directly. */
+int _range_enc_arfcns(enum gsm48_range range,
const int *arfcns, int size, int *out,
const int index)
{
@@ -99,16 +93,6 @@ int range_enc_arfcns(enum gsm48_range range,
int l_origin;
int r_origin;
-
- /* Test the two recursion anchors and stop processing */
- if (size == 0)
- return 0;
-
- if (size == 1) {
- out[index] = 1 + arfcns[0];
- return 0;
- }
-
/* Now do the processing */
split_at = range_enc_find_index(range, arfcns, size);
if (split_at < 0)
@@ -140,6 +124,28 @@ int range_enc_arfcns(enum gsm48_range range,
return 0;
}
+/**
+ * Range encode the ARFCN list.
+ * \param range The range to use.
+ * \param arfcns The list of ARFCNs
+ * \param size The size of the list of ARFCNs
+ * \param out Place to store the W(i) output.
+ */
+int range_enc_arfcns(enum gsm48_range range,
+ const int *arfcns, int size, int *out,
+ const int index)
+{
+ if (size <= 0)
+ return 0;
+
+ if (size == 1) {
+ out[index] = 1 + arfcns[0];
+ return 0;
+ }
+
+ return _range_enc_arfcns(range, arfcns, size, out, index);
+}
+
/*
* The easiest is to use f0 == arfcns[0]. This means that under certain
* circumstances we can encode less ARFCNs than possible with an optimal f0.