OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/xml-decode-uint32.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/xds/xml-decode-uint32.c 1.1 -> 1.2

--- 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 <stdio.h>
+#include <string.h>
+#include <ctype.h>
 #include <assert.h>
 #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, "<uint32>", 8) != 0)
+        return XDS_ERR_TYPE_MISMATCH;
+
+    /* Decode the representation of the value. */
 
     value = va_arg(*args, xds_uint32_t*);
-    rc = sscanf(buffer, "<uint32>%u</uint32>%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, "</uint32>", 9) != 0)
+        return XDS_ERR_TYPE_MISMATCH;
 
-    return len;
+    return p + 9 - (char*)buffer;
     }

CVSTrac 2.0.1