Remove Py_SSIZE2SIZE to quiet cppcheck warnings.
Tuple size cannot be negative and we already handle the case where it is zero.
This commit is contained in:
@@ -212,7 +212,7 @@ py_str_array_from_tuple(PyObject *py_tuple)
|
||||
Py_ssize_t tuple_size = PyTuple_Size(py_tuple);
|
||||
|
||||
// we need an extra 0 at the end
|
||||
char **result = calloc(Py_SSIZE2SIZE(tuple_size) + 1, sizeof(char*));
|
||||
char **result = calloc(tuple_size + 1, sizeof(char *));
|
||||
if (result == NULL) {
|
||||
debug_return_ptr(NULL);
|
||||
}
|
||||
|
@@ -52,7 +52,6 @@ struct PythonContext
|
||||
extern struct PythonContext py_ctx;
|
||||
|
||||
#define Py_TYPENAME(object) (object ? Py_TYPE(object)->tp_name : "NULL")
|
||||
#define Py_SSIZE2SIZE(value) ((value) < 0 ? 0 : (size_t)(value))
|
||||
|
||||
#define py_sudo_log(...) py_ctx.sudo_log(__VA_ARGS__)
|
||||
|
||||
|
@@ -137,7 +137,7 @@ sudo_module_ConvMessages_to_c(PyObject *py_tuple, Py_ssize_t *num_msgs, struct s
|
||||
debug_return_int(SUDO_RC_ERROR);
|
||||
}
|
||||
|
||||
*msgs = calloc(Py_SSIZE2SIZE(*num_msgs), sizeof(struct sudo_conv_message));
|
||||
*msgs = calloc(*num_msgs, sizeof(struct sudo_conv_message));
|
||||
if (*msgs == NULL) {
|
||||
debug_return_int(SUDO_RC_ERROR);
|
||||
}
|
||||
|
@@ -346,11 +346,12 @@ python_sudo_conversation(PyObject *Py_UNUSED(self), PyObject *py_args, PyObject
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* sudo_module_ConvMessages_to_c() returns error if no messages. */
|
||||
if (sudo_module_ConvMessages_to_c(py_args, &num_msgs, &msgs) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
replies = calloc(Py_SSIZE2SIZE(num_msgs), sizeof(struct sudo_conv_reply));
|
||||
replies = calloc(num_msgs, sizeof(struct sudo_conv_reply));
|
||||
if (replies == NULL)
|
||||
goto cleanup;
|
||||
py_result = PyTuple_New(num_msgs);
|
||||
|
Reference in New Issue
Block a user