]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.658 v7.3.658
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Sep 2012 17:09:11 +0000 (19:09 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Sep 2012 17:09:11 +0000 (19:09 +0200)
Problem:    NUL bytes truncate strings when converted from Python.
Solution:   Handle truncation as an error. (ZyX)

src/if_py_both.h
src/if_python3.c
src/version.c

index 3ab18516eb1089e76841f9e83c7972200aae413b..0031003eda4400063da880a1e2abc7573a16f0f2 100644 (file)
@@ -2530,8 +2530,10 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
 #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;
 
@@ -2549,7 +2551,8 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
        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;
 
@@ -2572,7 +2575,8 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
        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;
 
@@ -2587,8 +2591,10 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
     }
     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;
 
index 36ae8eb77855fcb79c78fab35334e329810e3626..0c10f8dbc717ccbdf1e98a19100cb00250303e02 100644 (file)
@@ -85,6 +85,7 @@ static void init_structs(void);
 #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 @@ static int py3initialised = 0;
 #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 @@ static int py3initialised = 0;
        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 \
index 3e0ac40f49b61feecfc24647d7db2c7355f64059..62bc81957fc26c46331d015696483d3fc8bde793 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    658,
 /**/
     657,
 /**/