This patch is to be applied on top of patch that disallows NUL bytes in 
dictionary keys.

# HG changeset patch
# User ZyX <[email protected]>
# Date 1346592005 -14400
# Node ID d998aa5da5a200f26fd3fb5cdc5b2ba503d22e46
# Parent  7d27a9afedaa06240a7fb2774000e26fe50cc324
Don’t allow NUL bytes in strings

diff -r 7d27a9afedaa -r d998aa5da5a2 src/if_py_both.h
--- a/src/if_py_both.h  Sat Sep 01 22:07:22 2012 +0400
+++ b/src/if_py_both.h  Sun Sep 02 17:19:40 2012 +0400
@@ -2535,8 +2535,10 @@
 #if PY_MAJOR_VERSION >= 3
     else if (PyBytes_Check(obj))
     {
-       char_u  *result = (char_u *) PyBytes_AsString(obj);
-
+       char_u  *result;
+
+       if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
+           return -1;
        if (result == NULL)
            return -1;
 
@@ -2554,7 +2556,8 @@
        if (bytes == NULL)
            return -1;
 
-       result = (char_u *) PyBytes_AsString(bytes);
+       if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
+           return -1;
        if (result == NULL)
            return -1;
 
@@ -2577,7 +2580,8 @@
        if (bytes == NULL)
            return -1;
 
-       result=(char_u *) PyString_AsString(bytes);
+       if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
+           return -1;
        if (result == NULL)
            return -1;
 
@@ -2592,8 +2596,10 @@
     }
     else if (PyString_Check(obj))
     {
-       char_u  *result = (char_u *) PyString_AsString(obj);
-
+       char_u  *result;
+
+       if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
+           return -1;
        if (result == NULL)
            return -1;
 
diff -r 7d27a9afedaa -r d998aa5da5a2 src/if_python3.c
--- a/src/if_python3.c  Sat Sep 01 22:07:22 2012 +0400
+++ b/src/if_python3.c  Sun Sep 02 17:19:40 2012 +0400
@@ -85,6 +85,7 @@
 #define PyString_AsString(obj) PyBytes_AsString(obj)
 #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
 #define PyString_FromString(repr) PyUnicode_FromString(repr)
+#define PyString_AsStringAndSize(obj, buffer, len) 
PyBytes_AsStringAndSize(obj, buffer, len)
 
 #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
 
@@ -552,7 +553,7 @@
 #define DICTKEY_GET(err) \
     if (PyBytes_Check(keyObject)) \
     { \
-       if (PyBytes_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
+       if (PyString_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
            return err; \
     } \
     else if (PyUnicode_Check(keyObject)) \
@@ -560,7 +561,7 @@
        bytes = PyString_AsBytes(keyObject); \
        if (bytes == NULL) \
            return err; \
-       if (PyBytes_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
+       if (PyString_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
            return err; \
     } \
     else \

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui