Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Coverity: false nesting #13775

Closed
p5pRT opened this issue Apr 26, 2014 · 11 comments
Closed

[PATCH] Coverity: false nesting #13775

p5pRT opened this issue Apr 26, 2014 · 11 comments
Labels

Comments

@p5pRT
Copy link

p5pRT commented Apr 26, 2014

Migrated from rt.perl.org#121744 (status was 'resolved')

Searchable as RT121744$

@p5pRT
Copy link
Author

p5pRT commented Apr 26, 2014

From @jhi

Indentation of the code lies about the logic.

Attached.

@p5pRT
Copy link
Author

p5pRT commented Apr 26, 2014

From @jhi

0001-Fix-for-Coverity-perl5-CID-29014.patch
From add64bbf239e11a941d7672b55c83d9eb93cda93 Mon Sep 17 00:00:00 2001
From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 23 Apr 2014 12:59:37 -0400
Subject: [PATCH] Fix for Coverity perl5 CID 29014: Nesting level does not
 match indentation (NESTING_INDENT_MISMATCH)

---
 util.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/util.c b/util.c
index 0a0ee40..3798621 100644
--- a/util.c
+++ b/util.c
@@ -2034,12 +2034,12 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
     }
     else
        safesysfree(environ[i]);
-       nlen = strlen(nam);
-       vlen = strlen(val);
+    nlen = strlen(nam);
+    vlen = strlen(val);
 
-       environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char));
-       /* all that work just for this */
-       my_setenv_format(environ[i], nam, nlen, val, vlen);
+    environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char));
+    /* all that work just for this */
+    my_setenv_format(environ[i], nam, nlen, val, vlen);
     } else {
 # endif
 #   if defined(__CYGWIN__)|| defined(__SYMBIAN32__) || defined(__riscos__)
-- 
1.9.2

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

From @tonycoz

On Sat Apr 26 12​:59​:37 2014, jhi wrote​:

Indentation of the code lies about the logic.

Added as a blocker, but I wonder if it wouldn't be better to just re-indent that whole if (!PL_use_safe_putenv) block.

Tony

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

From @jhi

On Sunday-201404-27, 23​:32, Tony Cook via RT wrote​:

On Sat Apr 26 12​:59​:37 2014, jhi wrote​:

Indentation of the code lies about the logic.

Added as a blocker, but I wonder if it wouldn't be better to just re-indent that whole if (!PL_use_safe_putenv) block.

Tony

I tried to keep the (whitespace) changes to minimum, but sure, works for
me, refreshed patch with more indentation attached.

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

From @jhi

0001-Fix-for-Coverity-perl5-CID-29014.patch
From add64bbf239e11a941d7672b55c83d9eb93cda93 Mon Sep 17 00:00:00 2001
From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 23 Apr 2014 12:59:37 -0400
Subject: [PATCH] Fix for Coverity perl5 CID 29014: Nesting level does not
 match indentation (NESTING_INDENT_MISMATCH)

---
 util.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/util.c b/util.c
index 0a0ee40..3798621 100644
--- a/util.c
+++ b/util.c
@@ -2034,12 +2034,12 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
     }
     else
        safesysfree(environ[i]);
-       nlen = strlen(nam);
-       vlen = strlen(val);
+    nlen = strlen(nam);
+    vlen = strlen(val);
 
-       environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char));
-       /* all that work just for this */
-       my_setenv_format(environ[i], nam, nlen, val, vlen);
+    environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char));
+    /* all that work just for this */
+    my_setenv_format(environ[i], nam, nlen, val, vlen);
     } else {
 # endif
 #   if defined(__CYGWIN__)|| defined(__SYMBIAN32__) || defined(__riscos__)
-- 
1.9.2

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

From @jhi

On Monday-201404-28, 7​:18, Jarkko Hietaniemi wrote​:

On Sunday-201404-27, 23​:32, Tony Cook via RT wrote​:

On Sat Apr 26 12​:59​:37 2014, jhi wrote​:

Indentation of the code lies about the logic.

Added as a blocker, but I wonder if it wouldn't be better to just re-indent that whole if (!PL_use_safe_putenv) block.

Tony

I tried to keep the (whitespace) changes to minimum, but sure, works for
me, refreshed patch with more indentation attached.

Argh. Take two of take two attached.

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

From @jhi

0001-Fix-for-Coverity-perl5-CID-29014.patch
From 273eb0474b161c9825fc94741964e2db147f5d45 Mon Sep 17 00:00:00 2001
From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 23 Apr 2014 12:59:37 -0400
Subject: [PATCH] Fix for Coverity perl5 CID 29014: Nesting level does not
 match indentation (NESTING_INDENT_MISMATCH)

---
 util.c | 92 +++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/util.c b/util.c
index 0a0ee40..11ff6a3 100644
--- a/util.c
+++ b/util.c
@@ -1992,54 +1992,54 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
   {
 #ifndef PERL_USE_SAFE_PUTENV
     if (!PL_use_safe_putenv) {
-    /* most putenv()s leak, so we manipulate environ directly */
-    I32 i;
-    const I32 len = strlen(nam);
-    int nlen, vlen;
-
-    /* where does it go? */
-    for (i = 0; environ[i]; i++) {
-        if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
-            break;
-    }
+        /* most putenv()s leak, so we manipulate environ directly */
+        I32 i;
+        const I32 len = strlen(nam);
+        int nlen, vlen;
+
+        /* where does it go? */
+        for (i = 0; environ[i]; i++) {
+            if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
+                break;
+        }
 
-    if (environ == PL_origenviron) {   /* need we copy environment? */
-       I32 j;
-       I32 max;
-       char **tmpenv;
-
-       max = i;
-       while (environ[max])
-           max++;
-       tmpenv = (char**)safesysmalloc((max+2) * sizeof(char*));
-       for (j=0; j<max; j++) {         /* copy environment */
-           const int len = strlen(environ[j]);
-           tmpenv[j] = (char*)safesysmalloc((len+1)*sizeof(char));
-           Copy(environ[j], tmpenv[j], len+1, char);
-       }
-       tmpenv[max] = NULL;
-       environ = tmpenv;               /* tell exec where it is now */
-    }
-    if (!val) {
-       safesysfree(environ[i]);
-       while (environ[i]) {
-           environ[i] = environ[i+1];
-           i++;
-	}
-       return;
-    }
-    if (!environ[i]) {                 /* does not exist yet */
-       environ = (char**)safesysrealloc(environ, (i+2) * sizeof(char*));
-       environ[i+1] = NULL;    /* make sure it's null terminated */
-    }
-    else
-       safesysfree(environ[i]);
-       nlen = strlen(nam);
-       vlen = strlen(val);
+        if (environ == PL_origenviron) {   /* need we copy environment? */
+            I32 j;
+            I32 max;
+            char **tmpenv;
+
+            max = i;
+            while (environ[max])
+                max++;
+            tmpenv = (char**)safesysmalloc((max+2) * sizeof(char*));
+            for (j=0; j<max; j++) {         /* copy environment */
+                const int len = strlen(environ[j]);
+                tmpenv[j] = (char*)safesysmalloc((len+1)*sizeof(char));
+                Copy(environ[j], tmpenv[j], len+1, char);
+            }
+            tmpenv[max] = NULL;
+            environ = tmpenv;               /* tell exec where it is now */
+        }
+        if (!val) {
+            safesysfree(environ[i]);
+            while (environ[i]) {
+                environ[i] = environ[i+1];
+                i++;
+            }
+            return;
+        }
+        if (!environ[i]) {                 /* does not exist yet */
+            environ = (char**)safesysrealloc(environ, (i+2) * sizeof(char*));
+            environ[i+1] = NULL;    /* make sure it's null terminated */
+        }
+        else
+            safesysfree(environ[i]);
+        nlen = strlen(nam);
+        vlen = strlen(val);
 
-       environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char));
-       /* all that work just for this */
-       my_setenv_format(environ[i], nam, nlen, val, vlen);
+        environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char));
+        /* all that work just for this */
+        my_setenv_format(environ[i], nam, nlen, val, vlen);
     } else {
 # endif
 #   if defined(__CYGWIN__)|| defined(__SYMBIAN32__) || defined(__riscos__)
-- 
1.9.2

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2014

From @khwilliamson

On 04/28/2014 05​:20 AM, Jarkko Hietaniemi wrote​:

I tried to keep the (whitespace) changes to minimum, but sure, works for
me, refreshed patch with more indentation attached.

The procedure we are using nowadays when there is non-trivial white
space changes which make diffs hard to read, is to do the white space
changes in a separate commit, and announce in the message that the only
changes are to white-space

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2014

From @tonycoz

On Mon Apr 28 04​:21​:12 2014, jhi wrote​:

On Monday-201404-28, 7​:18, Jarkko Hietaniemi wrote​:

On Sunday-201404-27, 23​:32, Tony Cook via RT wrote​:

On Sat Apr 26 12​:59​:37 2014, jhi wrote​:

Indentation of the code lies about the logic.

Added as a blocker, but I wonder if it wouldn't be better to just
re-indent that whole if (!PL_use_safe_putenv) block.

Tony

I tried to keep the (whitespace) changes to minimum, but sure, works
for
me, refreshed patch with more indentation attached.

Argh. Take two of take two attached.

Split and applied as 99e8c55 and b7d8786 by Jarkkoon the 29th.

Tony

@p5pRT p5pRT closed this as completed Jun 4, 2014
@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2014

@tonycoz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant