Move the string type max length definition into the config header so that the user can set them independently of MAX_APDU.

Also, added new define MAX_OCTET_STRING_BYTES.
This commit is contained in:
minack
2009-08-06 07:11:31 +00:00
parent a907edbfca
commit d5b455c742
3 changed files with 26 additions and 20 deletions
+2 -3
View File
@@ -38,16 +38,15 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "config.h"
/* bit strings /* bit strings
They could be as large as 256/8=32 octets */ They could be as large as 256/8=32 octets */
#define MAX_BITSTRING_BYTES 15
typedef struct BACnet_Bit_String { typedef struct BACnet_Bit_String {
uint8_t bits_used; uint8_t bits_used;
uint8_t value[MAX_BITSTRING_BYTES]; uint8_t value[MAX_BITSTRING_BYTES];
} BACNET_BIT_STRING; } BACNET_BIT_STRING;
#define MAX_CHARACTER_STRING_BYTES (MAX_APDU-6)
typedef struct BACnet_Character_String { typedef struct BACnet_Character_String {
size_t length; size_t length;
uint8_t encoding; uint8_t encoding;
@@ -60,7 +59,7 @@ typedef struct BACnet_Character_String {
typedef struct BACnet_Octet_String { typedef struct BACnet_Octet_String {
size_t length; size_t length;
/* limit - 6 octets is the most our tag and type could be */ /* limit - 6 octets is the most our tag and type could be */
uint8_t value[MAX_APDU - 6]; uint8_t value[MAX_OCTET_STRING_BYTES];
} BACNET_OCTET_STRING; } BACNET_OCTET_STRING;
#ifdef __cplusplus #ifdef __cplusplus
+6
View File
@@ -134,4 +134,10 @@
#define BACAPP_OBJECT_ID #define BACAPP_OBJECT_ID
#endif #endif
/*
** Set the maximum vector type sizes
*/
#define MAX_BITSTRING_BYTES (15)
#define MAX_CHARACTER_STRING_BYTES (MAX_APDU-6)
#define MAX_OCTET_STRING_BYTES (MAX_APDU-6)
#endif #endif
+18 -17
View File
@@ -167,7 +167,7 @@ uint8_t bitstring_bits_capacity(
BACNET_BIT_STRING * bit_string) BACNET_BIT_STRING * bit_string)
{ {
if (bit_string) { if (bit_string) {
return (sizeof(bit_string->value) * 8); return (MAX_BITSTRING_BYTES * 8);
} else { } else {
return 0; return 0;
} }
@@ -420,7 +420,7 @@ uint8_t characterstring_encoding(
} }
/* returns false if the string exceeds capacity /* returns false if the string exceeds capacity
initialize by using length=0 */ initialize by using value=0 */
bool octetstring_init( bool octetstring_init(
BACNET_OCTET_STRING * octet_string, BACNET_OCTET_STRING * octet_string,
uint8_t * value, uint8_t * value,
@@ -431,17 +431,18 @@ bool octetstring_init(
if (octet_string) { if (octet_string) {
octet_string->length = 0; octet_string->length = 0;
if (length <= sizeof(octet_string->value)) { if (value) {
if (value) { if (length <= MAX_OCTET_STRING_BYTES) {
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
octet_string->value[octet_string->length] = value[i]; octet_string->value[octet_string->length] = value[i];
octet_string->length++; octet_string->length++;
} }
} else { status = true;
for (i = 0; i < sizeof(octet_string->value); i++) { }
octet_string->value[i] = 0; } else {
} for (i = 0; i < MAX_OCTET_STRING_BYTES; i++) {
} octet_string->value[i] = 0;
}
status = true; status = true;
} }
} }
@@ -467,7 +468,7 @@ bool octetstring_append(
bool status = false; /* return value */ bool status = false; /* return value */
if (octet_string) { if (octet_string) {
if ((length + octet_string->length) <= sizeof(octet_string->value)) { if ((length + octet_string->length) <= MAX_OCTET_STRING_BYTES) {
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
octet_string->value[octet_string->length] = value[i]; octet_string->value[octet_string->length] = value[i];
octet_string->length++; octet_string->length++;
@@ -489,7 +490,7 @@ bool octetstring_truncate(
bool status = false; /* return value */ bool status = false; /* return value */
if (octet_string) { if (octet_string) {
if (length <= sizeof(octet_string->value)) { if (length <= MAX_OCTET_STRING_BYTES) {
octet_string->length = length; octet_string->length = length;
status = true; status = true;
} }
@@ -533,7 +534,7 @@ size_t octetstring_capacity(
if (octet_string) { if (octet_string) {
/* FIXME: validate length is within bounds? */ /* FIXME: validate length is within bounds? */
length = sizeof(octet_string->value); length = MAX_OCTET_STRING_BYTES;
} }
return length; return length;
@@ -548,7 +549,7 @@ bool octetstring_value_same(
if (octet_string1 && octet_string2) { if (octet_string1 && octet_string2) {
if ((octet_string1->length == octet_string2->length) && if ((octet_string1->length == octet_string2->length) &&
(octet_string1->length <= sizeof(octet_string1->value))) { (octet_string1->length <= MAX_OCTET_STRING_BYTES)) {
for (i = 0; i < octet_string1->length; i++) { for (i = 0; i < octet_string1->length; i++) {
if (octet_string1->value[i] != octet_string2->value[i]) { if (octet_string1->value[i] != octet_string2->value[i]) {
return false; return false;