OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/xml-encode-int32.c versions 1.3.2.1 and 1.3.2.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/xds/xml-encode-int32.c 1.3.2.1 -> 1.3.2.2

--- xml-encode-int32.c   2001/08/01 13:26:30     1.3.2.1
+++ xml-encode-int32.c   2001/08/01 15:08:02     1.3.2.2
@@ -28,7 +28,9 @@
 #include <string.h>
 #include "internal.h"
 
-int xml_encode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+int xml_encode_int32(xds_t* xds, void* engine_context,
+                     void* buffer, size_t buffer_size, size_t* used_buffer_size,
+                     va_list* args)
     {
     xds_int32_t value;
     char buf[32];
@@ -36,16 +38,10 @@
     char* p;
     int negative;
 
-    /* Consistency checks. */
+    xds_init_encoding_engine(7 + 8 + 11);
 
-    assert(xds != NULL);
-    assert(buffer != NULL);
-    assert(buffer_size != 0);
-    assert(args != NULL);
-    if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
-        return XDS_ERR_INVALID_ARG;
-
-    /* Format value into our buffer. */
+    /* Get the value and format it into our buffer. Keep track of the
+       length of the formatted result. */
 
     value = va_arg(*args, xds_int32_t);
     if (value < 0)
@@ -66,21 +62,18 @@
     if (negative)
         buf[i++] = '-';
 
-    /* Check the buffer size. */
-
-    if (buffer_size < 7 + 8 + i)
-        return 7 + 8 + i;
-
-    /* Write result into the buffer. */
+    /* Now that we know the correct size of our data's representation,
+       write it into the buffer. */
 
+    *used_buffer_size = 7 + 8 + i;
     p = buffer;
-    strcpy(p, "<int32>");
+    memmove(p, "<int32>", 7);
     p += 7;
     for (j = i; j > 0; )
         {
         *p++ = buf[--j];
         }
-    strcpy(p, "</int32>");
+    memmove(p, "</int32>", 8);
 
-    return 7 + 8 + i;
+    return XDS_OK;
     }

CVSTrac 2.0.1