develooper Front page | perl.perl5.porters | Postings from May 2013

[perl #117865] [PATCH] Eliminate useless variable and sizeof(char)

From:
Dagfinn Ilmari Mannsåker
Date:
May 4, 2013 23:50
Subject:
[perl #117865] [PATCH] Eliminate useless variable and sizeof(char)
Message ID:
rt-3.6.HEAD-28177-1367711422-475.117865-75-0@perl.org
# New Ticket Created by  Dagfinn Ilmari Mannsåker 
# Please include the string:  [perl #117865]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=117865 >


bufsiz is always just set from bsiz (via a useless multiplication by
sizeof(char), which is by definition 1), so instead of trying to keep
them in sync, just get rid of bufsiz use bsiz directly
---
 util.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/util.c b/util.c
index 42fd70f..1530f7b 100644
--- a/util.c
+++ b/util.c
@@ -6117,16 +6117,14 @@ Perl_my_clearenv(pTHX)
     (void)clearenv();
 #        elif defined(HAS_UNSETENV)
     int bsiz = 80; /* Most envvar names will be shorter than this. */
-    int bufsiz = bsiz * sizeof(char); /* sizeof(char) paranoid? */
-    char *buf = (char*)safesysmalloc(bufsiz);
+    char *buf = (char*)safesysmalloc(bsiz);
     while (*environ != NULL) {
       char *e = strchr(*environ, '=');
       int l = e ? e - *environ : (int)strlen(*environ);
       if (bsiz < l + 1) {
         (void)safesysfree(buf);
         bsiz = l + 1; /* + 1 for the \0. */
-        bufsiz = bsiz * sizeof(char); /* keep bsiz and bufsiz in sync */
-        buf = (char*)safesysmalloc(bufsiz);
+        buf = (char*)safesysmalloc(bsiz);
       } 
       memcpy(buf, *environ, l);
       buf[l] = '\0';
-- 
1.8.1.2




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About