aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-11-28 12:11:39 -0800
committerGuy Harris <guy@alum.mit.edu>2015-11-28 20:12:33 +0000
commitdba17518dfd611f84e87a95143f1058e05bca9f8 (patch)
tree84fffb143f34b190077159806fc4dc4e0687791b /wiretap
parentb8fa3d463c1bdd9b84c897441e7a5c8ad1f0f292 (diff)
Make it more obvious why no bounds checks are necessary for 11n.
For unsigned x, x/8 is x >> 3, and x*8 is x << 3, so 8*(x/8) is the result of shifting x right 3 bits and then left 3 bits, which is the same as masking out the low-order 3 bits, and x - (8*x/8) is the result of subtracting all but the low-order 3 bits from x, thus it's the lower 3 bits, so you can just mask it with 0x7. That means the result is in the range 0 through 7, so as long as the array has 8 elements, you're OK; it does, but explicitly declare it as such, to make it clearer that it is, and to get compiler warnings if not all 8 elements are initialized. Change-Id: Iff9c0626b9bdc012cca52e4160dda9e947315bc4 Reviewed-on: https://code.wireshark.org/review/12264 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/vwr.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/wiretap/vwr.c b/wiretap/vwr.c
index 3b9659322d..a699d8d6b9 100644
--- a/wiretap/vwr.c
+++ b/wiretap/vwr.c
@@ -2262,14 +2262,13 @@ static float getRate( guint8 plcpType, guint8 mcsIndex, guint16 rflags, guint8 n
/* Rate conversion data */
float canonical_rate_legacy[] = {1.0f, 2.0f, 5.5f, 11.0f, 6.0f, 9.0f, 12.0f, 18.0f, 24.0f, 36.0f, 48.0f, 54.0f};
- int canonical_ndbps_20_ht[] = {26, 52, 78, 104, 156, 208, 234, 260};
- int canonical_ndbps_40_ht[] = {54, 108, 162, 216, 324, 432, 486, 540};
+ int canonical_ndbps_20_ht[8] = {26, 52, 78, 104, 156, 208, 234, 260};
+ int canonical_ndbps_40_ht[8] = {54, 108, 162, 216, 324, 432, 486, 540};
int canonical_ndbps_20_vht[] = {26,52, 78, 104, 156, 208, 234, 260, 312};
int canonical_ndbps_40_vht[] = {54, 108, 162, 216, 324, 432, 486, 540, 648, 720};
int canonical_ndbps_80_vht[] = {117, 234, 351, 468, 702, 936, 1053, 1170, 1404, 1560};
- int ndbps;
float symbol_tx_time, bitrate = 0.0f;
if (plcpType == 0)
@@ -2279,17 +2278,19 @@ static float getRate( guint8 plcpType, guint8 mcsIndex, guint16 rflags, guint8 n
}
else if (plcpType == 1 || plcpType == 2)
{
+ int ndbps;
+
if ( rflags & FLAGS_CHAN_SHORTGI)
symbol_tx_time = 3.6f;
else
symbol_tx_time = 4.0f;
if ( rflags & FLAGS_CHAN_40MHZ )
- ndbps = canonical_ndbps_40_ht[ mcsIndex - 8*(int)(mcsIndex/8) ];
+ ndbps = canonical_ndbps_40_ht[mcsIndex & 0x07];
else
- ndbps = canonical_ndbps_20_ht[ mcsIndex - 8*(int)(mcsIndex/8) ];
+ ndbps = canonical_ndbps_20_ht[mcsIndex & 0x07];
- bitrate = ( ndbps * (((int)(mcsIndex/8) + 1) )) / symbol_tx_time;
+ bitrate = ( ndbps * (((int)(mcsIndex >> 3) + 1) )) / symbol_tx_time;
}
else
{