OSSP CVS Repository

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

ossp-pkg/xds/xml-decode-uint64.c 1.2 -> 1.3

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

CVSTrac 2.0.1