From 5efaafe278314051661c99c1e33a00d0883025a6 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 31 Jan 2019 19:43:30 +0100 Subject: Fixed mistakes relative to PyUnicode_Check() return value. --- plugins/pychrysalide/analysis/db/certs.c | 2 +- plugins/pychrysalide/analysis/routine.c | 6 +++--- plugins/pychrysalide/analysis/variable.c | 6 +++--- plugins/pychrysalide/helpers.c | 2 +- tests/analysis/routine.py | 21 +++++++++++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 tests/analysis/routine.py diff --git a/plugins/pychrysalide/analysis/db/certs.c b/plugins/pychrysalide/analysis/db/certs.c index 61b5f58..5fd2034 100644 --- a/plugins/pychrysalide/analysis/db/certs.c +++ b/plugins/pychrysalide/analysis/db/certs.c @@ -78,7 +78,7 @@ static bool py_certs_fill_x509_entries(PyObject *dict, x509_entries *out) { \ result = PyUnicode_Check(value); \ if (result) \ - out->dest = strdup((char *)PyUnicode_DATA(value)); \ + out->dest = strdup(PyUnicode_DATA(value)); \ else \ PyErr_Format(PyExc_TypeError, _("The %s property must be a string."), name); \ } \ diff --git a/plugins/pychrysalide/analysis/routine.c b/plugins/pychrysalide/analysis/routine.c index 1f245ae..d8b0eb7 100644 --- a/plugins/pychrysalide/analysis/routine.c +++ b/plugins/pychrysalide/analysis/routine.c @@ -301,10 +301,10 @@ static int py_binary_routine_set_name(PyObject *self, PyObject *value, void *clo routine = G_BIN_ROUTINE(pygobject_get(self)); - if (!PyUnicode_Check(value)) - g_binary_routine_set_name(routine, strdup(PyUnicode_DATA(value))); - else + if (value == Py_None) g_binary_routine_set_name(routine, NULL); + else + g_binary_routine_set_name(routine, strdup(PyUnicode_DATA(value))); return 0; diff --git a/plugins/pychrysalide/analysis/variable.c b/plugins/pychrysalide/analysis/variable.c index 030b26f..8af7e1d 100644 --- a/plugins/pychrysalide/analysis/variable.c +++ b/plugins/pychrysalide/analysis/variable.c @@ -178,10 +178,10 @@ static int py_binary_variable_set_name(PyObject *self, PyObject *value, void *cl variable = G_BIN_VARIABLE(pygobject_get(self)); - if (!PyUnicode_Check(value)) - g_binary_variable_set_name(variable, PyUnicode_DATA(value)); - else + if (value == Py_None) g_binary_variable_set_name(variable, NULL); + else + g_binary_variable_set_name(variable, PyUnicode_DATA(value)); return 0; diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c index a0aa5e7..f744475 100644 --- a/plugins/pychrysalide/helpers.c +++ b/plugins/pychrysalide/helpers.c @@ -239,7 +239,7 @@ PyObject *run_python_method(PyObject *module, const char *method, PyObject *args PyErr_Fetch(&type, &value, &traceback); if (type != NULL && type == PyExc_NotImplementedError \ - && value != NULL && PyUnicode_Check(value) == 1) + && value != NULL && PyUnicode_Check(value)) { refmsg = PyUnicode_FromString(NOT_IMPLEMENTED_MSG); diff --git a/tests/analysis/routine.py b/tests/analysis/routine.py new file mode 100644 index 0000000..da54ee9 --- /dev/null +++ b/tests/analysis/routine.py @@ -0,0 +1,21 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +from chrysacase import ChrysalideTestCase +from pychrysalide.analysis import BinRoutine + + +class TestBinaryRoutines(ChrysalideTestCase): + """TestCase for binary routine.""" + + def testUnicodeName(self): + """Ensure Unicode checks are well performed.""" + + name = 'ABC' + + r = BinRoutine() + + r.name = name + + self.assertEqual(r.name, name) -- cgit v0.11.2-87-g4458