aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2018-03-03 16:22:33 +0100
committerAnders Broman <a.broman58@gmail.com>2018-03-04 07:47:09 +0000
commit4630b4fcf835b91d043ad12818d666c7321e28a4 (patch)
tree750f514a890257775ec86b9a3596f7bca873436d
parent59af408e9ead20d96fb2991a7c629534939475d0 (diff)
clean up tvb_get_guintvar() a bit more
Wrap long lines. Use a do-while loop. We know up-front that we'll go into the loop at least once. Remove the cont variable, use the exit condition directly. Set *octetCount = 0 if we return 0 because of an error. In that case, we did not process any bytes and should inform the caller about this. Change-Id: I222270939e42e0096b6f5a25b197bd4bae12235e Reviewed-on: https://code.wireshark.org/review/26245 Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/dissectors/packet-wap.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/epan/dissectors/packet-wap.c b/epan/dissectors/packet-wap.c
index 8ce95dc709..1bf4857d51 100644
--- a/epan/dissectors/packet-wap.c
+++ b/epan/dissectors/packet-wap.c
@@ -28,44 +28,49 @@
* the final value. Can be pre-initialised to start at offset+count.
*/
guint
-tvb_get_guintvar (tvbuff_t *tvb, guint offset, guint *octetCount, packet_info *pinfo, expert_field *ei)
+tvb_get_guintvar (tvbuff_t *tvb, guint offset,
+ guint *octetCount, packet_info *pinfo, expert_field *ei)
{
guint value = 0;
guint octet;
guint counter = 0;
- char cont = 1;
#ifdef DEBUG
fprintf (stderr,
"dissect_wap: Starting tvb_get_guintvar at offset %d\n", offset);
#endif
- while (cont != 0)
- {
- value <<= 7; /* Value only exists in 7 of the 8 bits */
+ do {
octet = tvb_get_guint8 (tvb, offset+counter);
- counter += 1;
- value += (octet & 0x7F);
- cont = (octet & 0x80);
+
+ counter++;
+ if (counter > sizeof(value)) {
+ proto_tree_add_expert(NULL, pinfo, ei, tvb, offset, counter);
+ value = 0;
+ counter = 0;
+ break;
+ }
+
+ value <<= 7; /* Value only exists in 7 of the 8 bits */
+ value += (octet & 0x7F);
+
#ifdef DEBUG
- fprintf (stderr, "dissect_wap: computing: octet is %d (0x%02x), count=%d, value=%d, cont=%d\n",
- octet, octet, counter, value, cont);
+ fprintf(stderr,
+ "dissect_wap: computing: octet is %d (0x%02x), count=%d, value=%d\n",
+ octet, octet, counter, value);
#endif
- }
+ } while (octet & 0x80);
- if (counter > sizeof(value)) {
- proto_tree_add_expert(NULL, pinfo, ei, tvb, offset, counter);
- value = 0;
- }
- if (octetCount != NULL)
- {
- *octetCount = counter;
#ifdef DEBUG
- fprintf (stderr, "dissect_wap: Leaving tvb_get_guintvar count=%d, value=%u\n", *octetCount, value);
+ fprintf (stderr,
+ "dissect_wap: Leaving tvb_get_guintvar count=%d, value=%u\n",
+ counter, value);
#endif
- }
- return (value);
+ if (octetCount)
+ *octetCount = counter;
+
+ return value;
}
/*