Corrected PrivateTransfer unit tests.

Fixed hex-ascii conversion for zero length string. Fixed Octet-string unit test in BACnet application. Bug found by unit test.
This commit is contained in:
skarg
2012-05-13 15:02:40 +00:00
parent c0f2af65e0
commit 173e9fb9a9
5 changed files with 62 additions and 32 deletions
+27 -21
View File
@@ -668,28 +668,34 @@ bool octetstring_init_ascii_hex(
if (octet_string) {
octet_string->length = 0;
while (ascii_hex[index] != 0) {
if (!isalnum(ascii_hex[index])) {
/* skip non-numeric or alpha */
index++;
continue;
if (ascii_hex[0] == 0) {
/* nothing to decode, so success! */
status = true;
} else {
while (ascii_hex[index] != 0) {
if (!isalnum(ascii_hex[index])) {
/* skip non-numeric or alpha */
index++;
continue;
}
if (ascii_hex[index+1] == 0) {
break;
}
hex_pair_string[0] = ascii_hex[index];
hex_pair_string[1] = ascii_hex[index+1];
value = (uint8_t)strtol(hex_pair_string, NULL, 16);
if (octet_string->length <= MAX_OCTET_STRING_BYTES) {
octet_string->value[octet_string->length] = value;
octet_string->length++;
/* at least one pair was decoded */
status = true;
} else {
break;
status = false;
}
/* set up for next pair */
index += 2;
}
if (ascii_hex[index+1] == 0) {
break;
}
hex_pair_string[0] = ascii_hex[index];
hex_pair_string[1] = ascii_hex[index+1];
value = (uint8_t)strtol(hex_pair_string, NULL, 16);
if (octet_string->length <= MAX_OCTET_STRING_BYTES) {
octet_string->value[octet_string->length] = value;
octet_string->length++;
status = true;
} else {
break;
status = false;
}
/* set up for next pair */
index += 2;
}
}