summaryrefslogtreecommitdiff
path: root/ASNMP/asnmp
diff options
context:
space:
mode:
authormrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-08-20 20:05:48 +0000
committermrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-08-20 20:05:48 +0000
commit869227cbe6cfb34689911d5efe582dd0932082ee (patch)
tree43c46baff5638a992bb172df8df29cddd41c55bb /ASNMP/asnmp
parentc88f0af78c734e4f6851b69ef7bb39a87f51a46a (diff)
downloadATCD-869227cbe6cfb34689911d5efe582dd0932082ee.tar.gz
rework api to deal properly with non-null terminated strings
in constructor(char *) and in set_data
Diffstat (limited to 'ASNMP/asnmp')
-rw-r--r--ASNMP/asnmp/octet.cpp29
-rw-r--r--ASNMP/asnmp/octet.h4
2 files changed, 13 insertions, 20 deletions
diff --git a/ASNMP/asnmp/octet.cpp b/ASNMP/asnmp/octet.cpp
index c76f5df3b97..b850b581228 100644
--- a/ASNMP/asnmp/octet.cpp
+++ b/ASNMP/asnmp/octet.cpp
@@ -77,14 +77,11 @@ OctetStr::OctetStr( const char * string, long size):
init_octet_smi(smival);
// check for null string
- if ( !string || !(z = ACE_OS::strlen( string)))
+ if ( !string)
return;
- if (size == -1)
- size = z;
-
- if (size > z)
- size = z;
+ if (size == -1) // calc if no length given - assume c style string
+ size = z = ACE_OS::strlen( string);
copy_octet_smi(smival, size, string, validity);
}
@@ -95,15 +92,16 @@ OctetStr::OctetStr( const char * string, long size):
void OctetStr::set_data( const SmiBYTE* string, long size)
{
size_t z;
- // check for null string
- if ( !string || !(z = ACE_OS::strlen( (char *)string)))
- return;
- if (size == -1)
- size = z;
-
- if (size > z)
+ // invalid args, set octetStr to not valid
+ if ( !string || !size) {
+ validity = FALSE;
return;
+ }
+
+ // assume non-zero terminated string
+ if (size == -1) // calc if no length given - assume c style string
+ size = z = ACE_OS::strlen( (char *)string);
// free up already used space
if ( smival.value.string.ptr ) {
@@ -111,11 +109,6 @@ void OctetStr::set_data( const SmiBYTE* string, long size)
}
smival.value.string.len = 0;
- // check for zero len
- if ( !string || !size) {
- validity = TRUE;
- return;
- }
copy_octet_smi(smival, size, (const char *)string, validity);
}
diff --git a/ASNMP/asnmp/octet.h b/ASNMP/asnmp/octet.h
index 3b3c9f6273f..6d63da92e48 100644
--- a/ASNMP/asnmp/octet.h
+++ b/ASNMP/asnmp/octet.h
@@ -45,7 +45,7 @@ class ACE_Export OctetStr: public SnmpSyntax
{
public:
OctetStr( const char *string = "", long size = -1);
- // constructor using a string, -1 will calc/use full string length
+ // construct octet from byte buffer, assume c style string if size == -1
OctetStr ( const OctetStr &octet);
// constructor using another octet object
@@ -57,7 +57,7 @@ public:
// syntax type
void set_data( const SmiBYTE* string, long int size = -1);
- // set the data on an already constructed Octet
+ // set octet from byte buffer, assume c style string if size == -1
OctetStr& operator=( const char *string);
// assignment to a string operator overloaded