fix 2nd address scanning bug, add some comments

code merge from arska/libmbus without debug
This commit is contained in:
Aarno Aukia
2013-11-07 11:14:15 +01:00
committed by Stefan Wahren
parent 0d9f83ba88
commit f42c56f19c

View File

@ -2414,6 +2414,7 @@ mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask)
if (mask[pos] == 'f' || mask[pos] == 'F') if (mask[pos] == 'f' || mask[pos] == 'F')
{ {
// mask[pos] is a wildcard -> enumerate all 0..9 at this position
i_start = 0; i_start = 0;
i_end = 9; i_end = 9;
} }
@ -2421,16 +2422,21 @@ mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask)
{ {
if (pos < 15) if (pos < 15)
{ {
// mask[pos] is not a wildcard -> don't iterate, recursively check pos+1
mbus_scan_2nd_address_range(handle, pos+1, mask); mbus_scan_2nd_address_range(handle, pos+1, mask);
} }
else else
{ {
// .. except if we're at the last pos (==15) and this isn't a wildcard we still need to send the probe
i_start = (int)(mask[pos] - '0'); i_start = (int)(mask[pos] - '0');
i_end = (int)(mask[pos] - '0'); i_end = (int)(mask[pos] - '0');
} }
} }
for (i = 0; i <= 9; i++) // skip the scanning if we're returning from the (pos < 15) case above
if (mask[pos] == 'f' || mask[pos] == 'F' || pos == 15)
{
for (i = i_start; i <= i_end; i++)
{ {
mask[pos] = '0'+i; mask[pos] = '0'+i;
@ -2461,6 +2467,7 @@ mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask)
return -1; return -1;
} }
} }
}
free(mask); free(mask);
return 0; return 0;