pytdbpack_pack_data: Oops, since B is separately encoded as buffer and
authorMartin Pool <mbp@samba.org>
Tue, 5 Nov 2002 02:54:07 +0000 (02:54 +0000)
committerMartin Pool <mbp@samba.org>
Tue, 5 Nov 2002 02:54:07 +0000 (02:54 +0000)
length we need separate counters traversing the format and value
sequences to pack them.
(This used to be commit 49a0ba46e6693bb819440d4ab40045afc4a7ae17)

source3/python/py_tdbpack.c

index ba1e86384ed4c9c34c42579d989f39fdf54dad0d..c68d6f8c57eb266aae7a37b9fe1e302f35fa759d 100644 (file)
@@ -600,14 +600,14 @@ pytdbpack_pack_data(const char *format_str,
                    PyObject *val_seq,
                    unsigned char *packed)
 {
-       int i;
+       int format_i, val_i = 0;
 
-       for (i = 0; format_str[i]; i++) {
-               char ch = format_str[i];
+       for (format_i = 0, val_i = 0; format_str[format_i]; format_i++) {
+               char ch = format_str[format_i];
                PyObject *val_obj;
 
                /* borrow a reference to the item */
-               val_obj = PySequence_GetItem(val_seq, i);
+               val_obj = PySequence_GetItem(val_seq, val_i++);
                if (!val_obj)
                        return NULL;
 
@@ -661,10 +661,13 @@ pytdbpack_pack_data(const char *format_str,
                        long size;
                        char *sval;
 
+                       if (!PyInt_Check(val_obj))
+                               return NULL;
+
                        size = PyInt_AsLong(val_obj);
                        pack_uint32(size, &packed);
 
-                       val_obj = PySequence_GetItem(val_seq, ++i);
+                       val_obj = PySequence_GetItem(val_seq, val_i++);
                        if (!val_obj)
                                return NULL;