Index: ossp-pkg/xds/xml-decode-double.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-double.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-double.c,v' 2>/dev/null --- xml-decode-double.c 2001/07/24 13:04:43 1.2 +++ xml-decode-double.c 2001/07/24 13:52:41 1.3 @@ -25,8 +25,6 @@ SUCH DAMAGE. */ -#include -#include #include "internal.h" int xml_decode_double(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) Index: ossp-pkg/xds/xml-decode-int32.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-int32.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-int32.c,v' 2>/dev/null --- xml-decode-int32.c 2001/07/23 15:57:47 1.1 +++ xml-decode-int32.c 2001/07/24 13:52:41 1.2 @@ -25,15 +25,16 @@ SUCH DAMAGE. */ -#include +#include +#include #include #include "internal.h" int xml_decode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_int32_t* value; - int len; + char* p; + int negative; /* Consistency checks. */ @@ -44,12 +45,45 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* The buffer must contain at least opening tag, closing tag and + one digit. Check whether it is large enough. */ + + if (buffer_size < 7 + 8 + 1) + return XDS_ERR_UNDERFLOW; + + /* Does the opening XML tag match? */ + + if (strncmp(buffer, "", 7) != 0) + return XDS_ERR_TYPE_MISMATCH; + + /* Decode the representation of the value. */ value = va_arg(*args, xds_int32_t*); - rc = sscanf(buffer, "%d%n", value, &len); - if (rc <= 0) + *value = 0; + p = (char*)buffer + 7; + if (*p == '-') + { + negative = XDS_TRUE; + ++p; + } + else + negative = XDS_FALSE; + while(isdigit(*p)) + { + if (p >= (char*)buffer + buffer_size) + return XDS_ERR_UNDERFLOW; + *value *= 10; + *value += *p++ - '0'; + } + if (negative) + *value = 0 - *value; + + /* Does the closing XML tag match? */ + + if (p+8 > (char*)buffer + buffer_size) return XDS_ERR_UNDERFLOW; + else if (strncmp(p, "", 8) != 0) + return XDS_ERR_TYPE_MISMATCH; - return len; + return p + 8 - (char*)buffer; } Index: ossp-pkg/xds/xml-decode-int64.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-int64.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-int64.c,v' 2>/dev/null --- xml-decode-int64.c 2001/07/23 16:40:38 1.2 +++ xml-decode-int64.c 2001/07/24 13:52:41 1.3 @@ -25,15 +25,16 @@ SUCH DAMAGE. */ -#include +#include +#include #include #include "internal.h" int xml_decode_int64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_int64_t* value; - int len; + char* p; + int negative; /* Consistency checks. */ @@ -44,12 +45,45 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* The buffer must contain at least opening tag, closing tag and + one digit. Check whether it is large enough. */ + + if (buffer_size < 7 + 8 + 1) + return XDS_ERR_UNDERFLOW; + + /* Does the opening XML tag match? */ + + if (strncmp(buffer, "", 7) != 0) + return XDS_ERR_TYPE_MISMATCH; + + /* Decode the representation of the value. */ value = va_arg(*args, xds_int64_t*); - rc = sscanf(buffer, "%lld%n", value, &len); - if (rc <= 0) + *value = 0; + p = (char*)buffer + 7; + if (*p == '-') + { + negative = XDS_TRUE; + ++p; + } + else + negative = XDS_FALSE; + while(isdigit(*p)) + { + if (p >= (char*)buffer + buffer_size) + return XDS_ERR_UNDERFLOW; + *value *= 10; + *value += *p++ - '0'; + } + if (negative) + *value = 0 - *value; + + /* Does the closing XML tag match? */ + + if (p+8 > (char*)buffer + buffer_size) return XDS_ERR_UNDERFLOW; + else if (strncmp(p, "", 8) != 0) + return XDS_ERR_TYPE_MISMATCH; - return len; + return p + 8 - (char*)buffer; } Index: ossp-pkg/xds/xml-decode-uint32.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-uint32.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-uint32.c,v' 2>/dev/null --- xml-decode-uint32.c 2001/07/23 16:17:43 1.1 +++ xml-decode-uint32.c 2001/07/24 13:52:41 1.2 @@ -25,15 +25,15 @@ SUCH DAMAGE. */ -#include +#include +#include #include #include "internal.h" int xml_decode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_uint32_t* value; - int len; + char* p; /* Consistency checks. */ @@ -44,12 +44,36 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* The buffer must contain at least opening tag, closing tag and + one digit. Check whether it is large enough. */ + + if (buffer_size < 8 + 9 + 1) + return XDS_ERR_UNDERFLOW; + + /* Does the opening XML tag match? */ + + if (strncmp(buffer, "", 8) != 0) + return XDS_ERR_TYPE_MISMATCH; + + /* Decode the representation of the value. */ value = va_arg(*args, xds_uint32_t*); - rc = sscanf(buffer, "%u%n", value, &len); - if (rc <= 0) + *value = 0; + p = (char*)buffer + 8; + while(isdigit(*p)) + { + if (p >= (char*)buffer + buffer_size) + return XDS_ERR_UNDERFLOW; + *value *= 10; + *value += *p++ - '0'; + } + + /* Does the closing XML tag match? */ + + if (p+9 > (char*)buffer + buffer_size) return XDS_ERR_UNDERFLOW; + else if (strncmp(p, "", 9) != 0) + return XDS_ERR_TYPE_MISMATCH; - return len; + return p + 9 - (char*)buffer; } Index: ossp-pkg/xds/xml-decode-uint64.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-uint64.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-decode-uint64.c,v' 2>/dev/null --- xml-decode-uint64.c 2001/07/23 16:40:38 1.2 +++ xml-decode-uint64.c 2001/07/24 13:52:41 1.3 @@ -25,15 +25,15 @@ SUCH DAMAGE. */ -#include +#include +#include #include #include "internal.h" int xml_decode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_uint64_t* value; - int len; + char* p; /* Consistency checks. */ @@ -44,12 +44,36 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* The buffer must contain at least opening tag, closing tag and + one digit. Check whether it is large enough. */ + + if (buffer_size < 8 + 9 + 1) + return XDS_ERR_UNDERFLOW; + + /* Does the opening XML tag match? */ + + if (strncmp(buffer, "", 8) != 0) + return XDS_ERR_TYPE_MISMATCH; + + /* Decode the representation of the value. */ value = va_arg(*args, xds_uint64_t*); - rc = sscanf(buffer, "%llu%n", value, &len); - if (rc <= 0) + *value = 0; + p = (char*)buffer + 8; + while(isdigit(*p)) + { + if (p >= (char*)buffer + buffer_size) + return XDS_ERR_UNDERFLOW; + *value *= 10; + *value += *p++ - '0'; + } + + /* Does the closing XML tag match? */ + + if (p+9 > (char*)buffer + buffer_size) return XDS_ERR_UNDERFLOW; + else if (strncmp(p, "", 9) != 0) + return XDS_ERR_TYPE_MISMATCH; - return len; + return p + 9 - (char*)buffer; } Index: ossp-pkg/xds/xml-encode-double.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-double.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-double.c,v' 2>/dev/null --- xml-encode-double.c 2001/07/24 13:04:43 1.2 +++ xml-encode-double.c 2001/07/24 13:52:41 1.3 @@ -25,8 +25,6 @@ SUCH DAMAGE. */ -#include -#include #include "internal.h" int xml_encode_double(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) Index: ossp-pkg/xds/xml-encode-int32.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-int32.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-int32.c,v' 2>/dev/null --- xml-encode-int32.c 2001/07/23 15:57:47 1.2 +++ xml-encode-int32.c 2001/07/24 13:52:41 1.3 @@ -25,14 +25,17 @@ SUCH DAMAGE. */ -#include +#include #include #include "internal.h" int xml_encode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_int32_t value; + char buf[32]; + size_t i, j; + char* p; + int negative; /* Consistency checks. */ @@ -43,13 +46,42 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* Format value into our buffer. */ value = va_arg(*args, xds_int32_t); - rc = snprintf(buffer, buffer_size, "%d", value); - if (rc < 0) - return buffer_size*2; - assert(rc >= 15); + if (value < 0) + { + negative = XDS_TRUE; + value = 0 - value; + } + else + negative = XDS_FALSE; + i = 0; + do + { + unsigned char remainder = value % 10; + value = value / 10; + buf[i++] = '0' + remainder; + } + while (value != 0); + if (negative) + buf[i++] = '-'; + + /* Check the buffer size. */ + + if (buffer_size < 7 + 8 + i) + return 7 + 8 + i; + + /* Write result into the buffer. */ + + p = buffer; + strcpy(p, ""); + p += 7; + for (j = i; j > 0; ) + { + *p++ = buf[--j]; + } + strcpy(p, ""); - return rc; + return 7 + 8 + i; } Index: ossp-pkg/xds/xml-encode-int64.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-int64.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-int64.c,v' 2>/dev/null --- xml-encode-int64.c 2001/07/23 16:40:38 1.2 +++ xml-encode-int64.c 2001/07/24 13:52:41 1.3 @@ -25,14 +25,17 @@ SUCH DAMAGE. */ -#include +#include #include #include "internal.h" int xml_encode_int64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_int64_t value; + char buf[64]; + size_t i, j; + char* p; + int negative; /* Consistency checks. */ @@ -43,13 +46,42 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* Format value into our buffer. */ value = va_arg(*args, xds_int64_t); - rc = snprintf(buffer, buffer_size, "%lld", value); - if (rc < 0) - return buffer_size*2; - assert(rc >= 15); + if (value < 0) + { + negative = XDS_TRUE; + value = 0 - value; + } + else + negative = XDS_FALSE; + i = 0; + do + { + unsigned char remainder = value % 10; + value = value / 10; + buf[i++] = '0' + remainder; + } + while (value != 0); + if (negative) + buf[i++] = '-'; + + /* Check the buffer size. */ + + if (buffer_size < 7 + 8 + i) + return 7 + 8 + i; + + /* Write result into the buffer. */ + + p = buffer; + strcpy(p, ""); + p += 7; + for (j = i; j > 0; ) + { + *p++ = buf[--j]; + } + strcpy(p, ""); - return rc; + return 7 + 8 + i; } Index: ossp-pkg/xds/xml-encode-uint32.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-uint32.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-uint32.c,v' 2>/dev/null --- xml-encode-uint32.c 2001/07/23 16:17:43 1.1 +++ xml-encode-uint32.c 2001/07/24 13:52:41 1.2 @@ -25,14 +25,16 @@ SUCH DAMAGE. */ -#include +#include #include #include "internal.h" int xml_encode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_uint32_t value; + char buf[32]; + size_t i, j; + char* p; /* Consistency checks. */ @@ -43,13 +45,33 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* Format value into our buffer. */ value = va_arg(*args, xds_uint32_t); - rc = snprintf(buffer, buffer_size, "%u", value); - if (rc < 0) - return buffer_size*2; - assert(rc >= 15); + i = 0; + do + { + unsigned char remainder = value % 10; + value = value / 10; + buf[i++] = '0' + remainder; + } + while (value != 0); + + /* Check the buffer size. */ + + if (buffer_size < 8 + 9 + i) + return 8 + 9 + i; + + /* Write result into the buffer. */ + + p = buffer; + strcpy(p, ""); + p += 8; + for (j = i; j > 0; ) + { + *p++ = buf[--j]; + } + strcpy(p, ""); - return rc; + return 8 + 9 + i; } Index: ossp-pkg/xds/xml-encode-uint64.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-uint64.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/xds/Attic/xml-encode-uint64.c,v' 2>/dev/null --- xml-encode-uint64.c 2001/07/23 16:40:38 1.2 +++ xml-encode-uint64.c 2001/07/24 13:52:41 1.3 @@ -25,14 +25,16 @@ SUCH DAMAGE. */ -#include +#include #include #include "internal.h" int xml_encode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args) { - int rc; xds_uint64_t value; + char buf[64]; + size_t i, j; + char* p; /* Consistency checks. */ @@ -43,13 +45,33 @@ if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL) return XDS_ERR_INVALID_ARG; - /* Format value into buffer. */ + /* Format value into our buffer. */ value = va_arg(*args, xds_uint64_t); - rc = snprintf(buffer, buffer_size, "%llu", value); - if (rc < 0) - return buffer_size*2; - assert(rc >= 15); + i = 0; + do + { + unsigned char remainder = value % 10; + value = value / 10; + buf[i++] = '0' + remainder; + } + while (value != 0); + + /* Check the buffer size. */ + + if (buffer_size < 8 + 9 + i) + return 8 + 9 + i; + + /* Write result into the buffer. */ + + p = buffer; + strcpy(p, ""); + p += 8; + for (j = i; j > 0; ) + { + *p++ = buf[--j]; + } + strcpy(p, ""); - return rc; + return 8 + 9 + i; }