summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2014-12-12 10:22:10 +0100
committerAleksander Morgado <aleksander@aleksander.es>2014-12-12 10:22:44 +0100
commitb84db57fe24652238a06c8aaff70f769ccfa6a0e (patch)
treedc5f6e83f3828bfef58590e8575ce9ee1bf5794d /build-aux
parentb9c3701e3371984736240d2dded70c2d52f3b46e (diff)
qmi-codegen: fix printing contents of structs with fixed sized strings
If the fixed sized string contains no characters or is shorter than the explicit size, NUL bytes will be included. If we try to append exactly the size of the string, we'll end up with embedded NULs in our string to print, so the actual output will be cut, even if the string is longer after the embedded NUL bytes. E.g.: >>>>>> TLV: >>>>>> type = "GERAN Info" (0x10) >>>>>> length = 61 >>>>>> value = 00:00:00:00:00:00:00:00:00:00:00:00:FF:FF:FF:FF:28:00:03:7D:6F:00:00:32:F4:51:B3:00:4D:00:11:2A:00:8A:3C:00:00:32:F4:51:B3:00:63:00:30:14:00:89:3C:00:00:32:F4:51:B3:00:59:00:11:0D:00 >>>>>> translated = [ cell_id = '0' plmn = ' With this fix, we avoid this by explicitly finishing ourselves the fixed sized string with a NUL byte, and then adding the C string as the non-fixed sized ones, i.e. until the first NUL byte is found. E.g.: >>>>>> TLV: >>>>>> type = "GERAN Info" (0x10) >>>>>> length = 61 >>>>>> value = 00:00:00:00:00:00:00:00:00:00:00:00:FF:FF:FF:FF:28:00:03:7D:6F:00:00:32:F4:51:B3:00:4D:00:11:2A:00:8A:3C:00:00:32:F4:51:B3:00:63:00:30:14:00:89:3C:00:00:32:F4:51:B3:00:59:00:11:0D:00 >>>>>> translated = [ cell_id = '0' plmn = '' lac = '0' geran_absolute_rf_channel_number = '0' base_station_identity_code = '0' timing_advance = '4294967295' rx_level = '40' cell = '{ [0] = '[ cell_id = '28541' plmn = '2\xf4Q' lac = '179' geran_absolute_rf_channel_number = '77' base_station_identity_code = '17' rx_level = '42' ] ' [1] = '[ cell_id = '15498' plmn = '2\xf4Q' lac = '179' geran_absolute_rf_channel_number = '99' base_station_identity_code = '48' rx_level = '20' ] ' [2] = '[ cell_id = '15497' plmn = '2\xf4Q' lac = '179' geran_absolute_rf_channel_number = '89' base_station_identity_code = '17' rx_level = '13' ] '}' ]
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/qmi-codegen/VariableString.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/build-aux/qmi-codegen/VariableString.py b/build-aux/qmi-codegen/VariableString.py
index f7e1dcb..b58a7d2 100644
--- a/build-aux/qmi-codegen/VariableString.py
+++ b/build-aux/qmi-codegen/VariableString.py
@@ -123,14 +123,16 @@ class VariableString(Variable):
if self.is_fixed_size:
translations['fixed_size'] = self.fixed_size
+ translations['fixed_size_plus_one'] = int(self.fixed_size) + 1
template = (
'\n'
'${lp}{\n'
- '${lp} gchar tmp[${fixed_size}];\n'
+ '${lp} gchar tmp[${fixed_size_plus_one}];\n'
'\n'
'${lp} if (!qmi_message_tlv_read_fixed_size_string (message, init_offset, &offset, ${fixed_size}, &tmp[0], &error))\n'
'${lp} goto out;\n'
- '${lp} g_string_append_len (printable, tmp, ${fixed_size});\n'
+ '${lp} tmp[${fixed_size}] = \'\\0\';\n'
+ '${lp} g_string_append (printable, tmp);\n'
'${lp}}\n')
else:
translations['n_size_prefix_bytes'] = self.n_size_prefix_bytes