diff options
author | Martin Pool <mbp@samba.org> | 2002-11-06 01:59:57 +0000 |
---|---|---|
committer | Martin Pool <mbp@samba.org> | 2002-11-06 01:59:57 +0000 |
commit | 6b0761b327ea5c0c4e8a4756d5e08374cc0d2c74 (patch) | |
tree | 764d4db6de128e175890adc85456e1b0bdffcbc6 | |
parent | 618db4e739ed06b8b02e5a390cd41f9a90a46807 (diff) | |
download | samba-6b0761b327ea5c0c4e8a4756d5e08374cc0d2c74.tar.gz samba-6b0761b327ea5c0c4e8a4756d5e08374cc0d2c74.tar.bz2 samba-6b0761b327ea5c0c4e8a4756d5e08374cc0d2c74.zip |
pytdbpack_unpack: Clean up, and correct the handling of '$'.
(This used to be commit dd73568f97ad51c93f096001058fd31fa14e88ae)
-rw-r--r-- | source3/python/py_tdbpack.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c index d29ada6741..87cd804ed4 100644 --- a/source3/python/py_tdbpack.c +++ b/source3/python/py_tdbpack.c @@ -209,8 +209,8 @@ pytdbpack_unpack(PyObject *self, PyObject *val_list = NULL, *ret_tuple = NULL; PyObject *rest_string = NULL; int format_len, packed_len; + char last_format = '#'; /* invalid */ int i; - char last_format = '#'; /* get arguments */ if (!PyArg_ParseTuple(args, "ss#", &format_str, &packed_str, &packed_len)) @@ -228,28 +228,26 @@ pytdbpack_unpack(PyObject *self, goto failed; /* For every object, unpack. */ - for (ppacked = packed_str, i = 0; i < format_len; i++) { - char format; - - format = format_str[i]; - if (format == '$') { - if (i == 0) { - PyErr_Format(PyExc_ValueError, - "%s: '$' may not be first character in format", - __FUNCTION__); - goto failed; - } - else { - format = last_format; /* repeat */ - } - } - - if (!pytdbpack_unpack_item(format, &ppacked, &packed_len, val_list)) + for (ppacked = packed_str, i = 0; i < format_len && format_str[i] != '$'; i++) { + last_format = format_str[i]; + /* packed_len is reduced in place */ + if (!pytdbpack_unpack_item(format_str[i], &ppacked, &packed_len, val_list)) goto failed; - - last_format = format; } + /* If the last character was '$', keep going until out of space */ + if (format_str[i] == '$') { + if (i == 0) { + PyErr_Format(PyExc_ValueError, + "%s: '$' may not be first character in format", + __FUNCTION__); + return NULL; + } + while (packed_len > 0) + if (!pytdbpack_unpack_item(last_format, &ppacked, &packed_len, val_list)) + goto failed; + } + /* save leftovers for next time */ rest_string = PyString_FromStringAndSize(ppacked, packed_len); if (!rest_string) |