libsmbconf: Avoid initial declaration inside 'for' loop
authorAnoop C S <anoopcs@samba.org>
Mon, 25 Apr 2022 06:54:28 +0000 (12:24 +0530)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 25 Apr 2022 13:23:18 +0000 (13:23 +0000)
Building Samba on CentOS 7 with GCC version 4.8.5 results in the
following error:

[2725/3398] Compiling libcli/echo/tests/echo.c
../../lib/smbconf/pysmbconf.c: In function 'py_from_smbconf_service':
../../lib/smbconf/pysmbconf.c:72:2: error: 'for' loop initial
                               declarations are only allowed in C99 mode
  for (uint32_t i = 0; i < svc->num_params; i++) {
  ^
../../lib/smbconf/pysmbconf.c:72:2: note: use option -std=c99 or
                                         -std=gnu99 to compile your code
../../lib/smbconf/pysmbconf.c: In function 'obj_share_names':
../../lib/smbconf/pysmbconf.c:181:2: error: 'for' loop initial
                               declarations are only allowed in C99 mode
  for (uint32_t i = 0; i < num_shares; i++) {
  ^
../../lib/smbconf/pysmbconf.c: In function 'obj_get_config':
../../lib/smbconf/pysmbconf.c:267:2: error: 'for' loop initial
                               declarations are only allowed in C99 mode
  for (uint32_t i = 0; i < num_shares; i++) {
  ^

Therefore declare variables right at the start aligning to default C90
standard available with GCC version on CentOS 7.

Signed-off-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Mon Apr 25 13:23:18 UTC 2022 on sn-devel-184

lib/smbconf/pysmbconf.c

index 0a5c3a6980c7eff72a67f79d92fcd7df3e5e25bd..abf77ddc1eb6dd012834ced838397f556ebed88d 100644 (file)
@@ -64,20 +64,21 @@ static void py_raise_SMBConfError(sbcErr err)
  */
 static PyObject *py_from_smbconf_service(struct smbconf_service *svc)
 {
+       uint32_t count;
        PyObject *plist = PyList_New(svc->num_params);
        if (plist == NULL) {
                return NULL;
        }
 
-       for (uint32_t i = 0; i < svc->num_params; i++) {
+       for (count = 0; count < svc->num_params; count++) {
                PyObject *pt = Py_BuildValue("(ss)",
-                                            svc->param_names[i],
-                                            svc->param_values[i]);
+                                            svc->param_names[count],
+                                            svc->param_values[count]);
                if (pt == NULL) {
                        Py_CLEAR(plist);
                        return NULL;
                }
-               if (PyList_SetItem(plist, i, pt) < 0) {
+               if (PyList_SetItem(plist, count, pt) < 0) {
                        Py_CLEAR(pt);
                        Py_CLEAR(plist);
                        return NULL;
@@ -149,6 +150,7 @@ static PyObject *obj_share_names(py_SMBConf_Object * self,
                                 PyObject * Py_UNUSED(ignored))
 {
        sbcErr err;
+       uint32_t count;
        uint32_t num_shares;
        char **share_names = NULL;
        PyObject *slist = NULL;
@@ -178,14 +180,14 @@ static PyObject *obj_share_names(py_SMBConf_Object * self,
                talloc_free(mem_ctx);
                return NULL;
        }
-       for (uint32_t i = 0; i < num_shares; i++) {
-               PyObject *ustr = PyUnicode_FromString(share_names[i]);
+       for (count = 0; count < num_shares; count++) {
+               PyObject *ustr = PyUnicode_FromString(share_names[count]);
                if (ustr == NULL) {
                        Py_CLEAR(slist);
                        talloc_free(mem_ctx);
                        return NULL;
                }
-               if (PyList_SetItem(slist, i, ustr) < 0) {
+               if (PyList_SetItem(slist, count, ustr) < 0) {
                        Py_CLEAR(ustr);
                        Py_CLEAR(slist);
                        talloc_free(mem_ctx);
@@ -239,6 +241,7 @@ static PyObject *obj_get_config(py_SMBConf_Object * self,
        sbcErr err;
        PyObject *svclist = NULL;
        TALLOC_CTX *mem_ctx = NULL;
+       uint32_t count;
        uint32_t num_shares;
        struct smbconf_service **svcs = NULL;
 
@@ -264,14 +267,14 @@ static PyObject *obj_get_config(py_SMBConf_Object * self,
                talloc_free(mem_ctx);
                return NULL;
        }
-       for (uint32_t i = 0; i < num_shares; i++) {
-               PyObject *svcobj = py_from_smbconf_service(svcs[i]);
+       for (count = 0; count < num_shares; count++) {
+               PyObject *svcobj = py_from_smbconf_service(svcs[count]);
                if (svcobj == NULL) {
                        Py_CLEAR(svclist);
                        talloc_free(mem_ctx);
                        return NULL;
                }
-               if (PyList_SetItem(svclist, i, svcobj) < 0) {
+               if (PyList_SetItem(svclist, count, svcobj) < 0) {
                        Py_CLEAR(svcobj);
                        Py_CLEAR(svclist);
                        talloc_free(mem_ctx);