Replace:
int i;
for (i = 0; ...)
With:
for (int i = 0; ...)
This removes unneeded variable from the function, and limit the scope of
the counter to the loop.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 2216322..ed9de0f 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -173,11 +173,11 @@ finally:
}
static int
parse_disks(PyObject *obj, struct sanlk_resource **res_ret)
{
- int i, num_disks, res_len;
+ int num_disks, res_len;
struct sanlk_resource *res;
num_disks = PyList_Size(obj);
res_len = sizeof(struct sanlk_resource) +
@@ -190,11 +190,11 @@ parse_disks(PyObject *obj, struct sanlk_resource **res_ret)
}
memset(res, 0, res_len);
res->num_disks = num_disks;
- for (i = 0; i < num_disks; i++) {
+ for (int i = 0; i < num_disks; i++) {
PyObject *disk = PyList_GetItem(obj,i);
if (!parse_single_disk(disk, &(res->disks[i]))) {
goto exit_fail;
}
@@ -269,18 +269,17 @@ set_error(PyObject* exception, const char* format, PyObject* obj)
}
static PyObject *
hosts_to_list(struct sanlk_host *hss, int hss_count)
{
- int i;
PyObject *ls_list = NULL, *ls_entry = NULL;
/* prepare the dictionary holding the information */
if ((ls_list = PyList_New(0)) == NULL)
goto exit_fail;
- for (i = 0; i < hss_count; i++) {
+ for (int i = 0; i < hss_count; i++) {
/* fill the dictionary information */
ls_entry = Py_BuildValue(
"{s:K,s:K,s:K,s:I,s:I}",
"host_id", hss[i].host_id,
@@ -979,11 +978,11 @@ process of being acquired, and LSFLAG_REM if it's in the process
of being\n\
released.\n");
static PyObject *
py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, i, lss_count;
+ int rv, lss_count;
struct sanlk_lockspace *lss = NULL;
PyObject *ls_list = NULL, *ls_entry = NULL;
/* get all the lockspaces (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -997,11 +996,11 @@ py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject
*keywds)
/* prepare the dictionary holding the information */
if ((ls_list = PyList_New(0)) == NULL)
goto exit_fail;
- for (i = 0; i < lss_count; i++) {
+ for (int i = 0; i < lss_count; i++) {
/* fill the dictionary information */
ls_entry = Py_BuildValue(
#if PY_MAJOR_VERSION == 2
"{s:s,s:K,s:s,s:K,s:I}",
@@ -1352,12 +1351,12 @@ finally:
}
static int
parse_killpath_item(PyObject *item, char *kpargs, size_t *kplen)
{
- int rv = 0, i;
- size_t arg_len;
+ int rv = 0;
+ size_t arg_len = 0;
PyObject *path = NULL;
const char *p = NULL;
if (!pypath_converter(item, &path)) {
goto finally;
@@ -1365,11 +1364,11 @@ parse_killpath_item(PyObject *item, char *kpargs, size_t *kplen)
p = PyBytes_AsString(path);
if (!p) {
goto finally;
}
/* computing the argument length considering the escape chars */
- for (i = 0, arg_len = 0; p[i]; i++, arg_len++) {
+ for (int i = 0; p[i]; i++, arg_len++) {
if (p[i] == ' ' || p[i] == '\\') arg_len++;
}
/* adding 2 for the space separator ' ' and the '\0' terminator */
if (*kplen + arg_len + 2 > SANLK_HELPER_ARGS_LEN) {
@@ -1405,12 +1404,12 @@ a safe state (resources released).\n\
The arguments must be in the format: [\"arg1\", \"arg2\",
...]");
static PyObject *
py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv = -1, i, num_args, sanlockfd = -1;
- size_t kplen;
+ int rv = -1, num_args, sanlockfd = -1;
+ size_t kplen = 0;
char kpargs[SANLK_HELPER_ARGS_LEN];
PyObject *path = NULL;
PyObject *argslist;
static char *kwlist[] = {"path", "args", "slkfd",
NULL};
@@ -1429,11 +1428,11 @@ py_killpath(PyObject *self __unused, PyObject *args, PyObject
*keywds)
num_args = PyList_Size(argslist);
memset(kpargs, 0, SANLK_HELPER_ARGS_LEN);
/* creating the arguments string from a python list */
- for (i = 0, kplen = 0; i < num_args; i++) {
+ for (int i = 0; i < num_args; i++) {
PyObject *item = PyList_GetItem(argslist, i);
if (!parse_killpath_item(item, kpargs, &kplen)) {
goto finally;
}
}
--
2.17.2