gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, wasted-byte, created. gawk-4.1.0-1011-gb


From: Andrew J. Schorr
Subject: [gawk-diffs] [SCM] gawk branch, wasted-byte, created. gawk-4.1.0-1011-gb6ac928
Date: Sun, 14 Dec 2014 15:41:13 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, wasted-byte has been created
        at  b6ac928a53d146233741fc5f7fe1cac66de27303 (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=b6ac928a53d146233741fc5f7fe1cac66de27303

commit b6ac928a53d146233741fc5f7fe1cac66de27303
Author: Andrew J. Schorr <address@hidden>
Date:   Sun Dec 14 10:27:32 2014 -0500

    Stop allocating an extra wasted byte at the end of various strings.

diff --git a/ChangeLog b/ChangeLog
index a9c7e55..c54a177 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2014-12-14         Andrew J. Schorr     <address@hidden>
+
+       * array.c (concat_exp): Do not waste a byte at the end of a string.
+       * awkgram.y (common_exp): Ditto.
+       * builtin.c (do_substr): Ditto.
+       * eval.c (set_OFS): Ditto.
+       * field.c (rebuild_record): Ditto.
+       * gawkapi.h (r_make_string): Ditto.
+       * interpret.h (r_interpret): Ditto for Op_assign_concat.
+       * node.c (r_format_val, r_dupnode, make_str_node, str2wstr, wstr2str):
+       Ditto.
+       * re.c (make_regexp): Ditto.
+
 2014-12-12        Stephen Davies         <address@hidden>
 
        Improve comment handling in pretty printing.
diff --git a/array.c b/array.c
index f799362..59428ba 100644
--- a/array.c
+++ b/array.c
@@ -414,7 +414,7 @@ concat_exp(int nargs, bool do_subsep)
        }
        len += (nargs - 1) * subseplen;
 
-       emalloc(str, char *, len + 2, "concat_exp");
+       emalloc(str, char *, len + 1, "concat_exp");
 
        r = args_array[nargs];
        memcpy(str, r->stptr, r->stlen);
diff --git a/awkgram.c b/awkgram.c
index 225cdb4..4715290 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -3398,7 +3398,7 @@ regular_print:
                        n1 = force_string(n1);
                        n2 = force_string(n2);
                        nlen = n1->stlen + n2->stlen;
-                       erealloc(n1->stptr, char *, nlen + 2, "constant fold");
+                       erealloc(n1->stptr, char *, nlen + 1, "constant fold");
                        memcpy(n1->stptr + n1->stlen, n2->stptr, n2->stlen);
                        n1->stlen = nlen;
                        n1->stptr[nlen] = '\0';
diff --git a/awkgram.y b/awkgram.y
index 6721bcd..f6a396a 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1442,7 +1442,7 @@ common_exp
                        n1 = force_string(n1);
                        n2 = force_string(n2);
                        nlen = n1->stlen + n2->stlen;
-                       erealloc(n1->stptr, char *, nlen + 2, "constant fold");
+                       erealloc(n1->stptr, char *, nlen + 1, "constant fold");
                        memcpy(n1->stptr + n1->stlen, n2->stptr, n2->stlen);
                        n1->stlen = nlen;
                        n1->stptr[nlen] = '\0';
diff --git a/builtin.c b/builtin.c
index 21c6ed5..838ab89 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1833,7 +1833,7 @@ do_substr(int nargs)
                 * way to do things.
                 */
                memset(& mbs, 0, sizeof(mbs));
-               emalloc(substr, char *, (length * gawk_mb_cur_max) + 2, 
"do_substr");
+               emalloc(substr, char *, (length * gawk_mb_cur_max) + 1, 
"do_substr");
                wp = t1->wstptr + indx;
                for (cp = substr; length > 0; length--) {
                        result = wcrtomb(cp, *wp, & mbs);
diff --git a/eval.c b/eval.c
index 9599270..eca829c 100644
--- a/eval.c
+++ b/eval.c
@@ -828,9 +828,9 @@ set_OFS()
        new_ofs_len = OFS_node->var_value->stlen;
 
        if (OFS == NULL)
-               emalloc(OFS, char *, new_ofs_len + 2, "set_OFS");
+               emalloc(OFS, char *, new_ofs_len + 1, "set_OFS");
        else if (OFSlen < new_ofs_len)
-               erealloc(OFS, char *, new_ofs_len + 2, "set_OFS");
+               erealloc(OFS, char *, new_ofs_len + 1, "set_OFS");
 
        memcpy(OFS, OFS_node->var_value->stptr, OFS_node->var_value->stlen);
        OFSlen = new_ofs_len;
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 41c8a0e..dca1433 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,10 @@
+2014-12-14         Andrew J. Schorr     <address@hidden>
+
+       * readfile.c (read_file_to_buffer): Do not waste a byte at the end of
+       a string.
+       * rwarray.c (read_value): Ditto.
+       * rwarray0.c (read_value): Ditto.
+
 2014-11-23         Arnold D. Robbins     <address@hidden>
 
        * inplace.c (do_inplace_begin): Jump through hoops to silence
diff --git a/extension/readfile.c b/extension/readfile.c
index d4b4aef..7673589 100644
--- a/extension/readfile.c
+++ b/extension/readfile.c
@@ -82,8 +82,8 @@ read_file_to_buffer(int fd, const struct stat *sbuf)
                goto done;
        }
 
-       emalloc(text, char *, sbuf->st_size + 2, "do_readfile");
-       memset(text, '\0', sbuf->st_size + 2);
+       emalloc(text, char *, sbuf->st_size + 1, "do_readfile");
+       memset(text, '\0', sbuf->st_size + 1);
 
        if ((ret = read(fd, text, sbuf->st_size)) != sbuf->st_size) {
                update_ERRNO_int(errno);
diff --git a/extension/rwarray.c b/extension/rwarray.c
index aa05a0d..5bead97 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -468,8 +468,8 @@ read_value(FILE *fp, awk_value_t *value)
                len = ntohl(len);
                value->val_type = AWK_STRING;
                value->str_value.len = len;
-               value->str_value.str = gawk_malloc(len + 2);
-               memset(value->str_value.str, '\0', len + 2);
+               value->str_value.str = gawk_malloc(len + 1);
+               memset(value->str_value.str, '\0', len + 1);
 
                if (fread(value->str_value.str, 1, len, fp) != (ssize_t) len) {
                        gawk_free(value->str_value.str);
diff --git a/extension/rwarray0.c b/extension/rwarray0.c
index e2de3cf..ec3663c 100644
--- a/extension/rwarray0.c
+++ b/extension/rwarray0.c
@@ -452,8 +452,8 @@ read_value(int fd, awk_value_t *value)
                len = ntohl(len);
                value->val_type = AWK_STRING;
                value->str_value.len = len;
-               value->str_value.str = malloc(len + 2);
-               memset(value->str_value.str, '\0', len + 2);
+               value->str_value.str = malloc(len + 1);
+               memset(value->str_value.str, '\0', len + 1);
 
                if (read(fd, value->str_value.str, len) != (ssize_t) len) {
                        free(value->str_value.str);
diff --git a/field.c b/field.c
index 6a7c6b1..c23f0b1 100644
--- a/field.c
+++ b/field.c
@@ -163,7 +163,7 @@ rebuild_record()
        tlen += (NF - 1) * OFSlen;
        if ((long) tlen < 0)
                tlen = 0;
-       emalloc(ops, char *, tlen + 2, "rebuild_record");
+       emalloc(ops, char *, tlen + 1, "rebuild_record");
        cops = ops;
        ops[0] = '\0';
        for (i = 1;  i <= NF; i++) {
diff --git a/gawkapi.h b/gawkapi.h
index d821545..b9dc2c0 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -791,7 +791,7 @@ r_make_string(const gawk_api_t *api,        /* needed for 
emalloc */
        result->str_value.len = length;
 
        if (duplicate) {
-               emalloc(cp, char *, length + 2, "r_make_string");
+               emalloc(cp, char *, length + 1, "r_make_string");
                memcpy(cp, string, length);
                cp[length] = '\0';
                result->str_value.str = cp;
diff --git a/interpret.h b/interpret.h
index 3a9cab3..665f6fa 100644
--- a/interpret.h
+++ b/interpret.h
@@ -709,7 +709,7 @@ mod:
                        if (t1 != t2 && t1->valref == 1 && (t1->flags & MPFN) 
== 0) {
                                size_t nlen = t1->stlen + t2->stlen;
 
-                               erealloc(t1->stptr, char *, nlen + 2, 
"r_interpret");
+                               erealloc(t1->stptr, char *, nlen + 1, 
"r_interpret");
                                memcpy(t1->stptr + t1->stlen, t2->stptr, 
t2->stlen);
                                t1->stlen = nlen;
                                t1->stptr[nlen] = '\0';
@@ -719,7 +719,7 @@ mod:
                                        size_t wlen = t1->wstlen + t2->wstlen;
 
                                        erealloc(t1->wstptr, wchar_t *,
-                                                       sizeof(wchar_t) * (wlen 
+ 2), "r_interpret");
+                                                       sizeof(wchar_t) * (wlen 
+ 1), "r_interpret");
                                        memcpy(t1->wstptr + t1->wstlen, 
t2->wstptr, t2->wstlen);
                                        t1->wstlen = wlen;
                                        t1->wstptr[wlen] = L'\0';
@@ -730,9 +730,10 @@ mod:
                                size_t nlen = t1->stlen + t2->stlen;  
                                char *p;
 
-                               emalloc(p, char *, nlen + 2, "r_interpret");
+                               emalloc(p, char *, nlen + 1, "r_interpret");
                                memcpy(p, t1->stptr, t1->stlen);
                                memcpy(p + t1->stlen, t2->stptr, t2->stlen);
+                               /* N.B. No NUL-termination required, since 
make_str_node will do it. */
                                unref(*lhs);
                                t1 = *lhs = make_str_node(p, nlen, 
ALREADY_MALLOCED); 
                        }
diff --git a/node.c b/node.c
index 507d065..869e4cb 100644
--- a/node.c
+++ b/node.c
@@ -252,7 +252,7 @@ r_format_val(const char *format, int index, NODE *s)
        }
        if (s->stptr != NULL)
                efree(s->stptr);
-       emalloc(s->stptr, char *, s->stlen + 2, "format_val");
+       emalloc(s->stptr, char *, s->stlen + 1, "format_val");
        memcpy(s->stptr, sp, s->stlen + 1);
 no_malloc:
        s->flags |= STRCUR;
@@ -290,12 +290,12 @@ r_dupnode(NODE *n)
        r->wstlen = 0;
 
        if ((n->flags & STRCUR) != 0) {
-               emalloc(r->stptr, char *, n->stlen + 2, "r_dupnode");
+               emalloc(r->stptr, char *, n->stlen + 1, "r_dupnode");
                memcpy(r->stptr, n->stptr, n->stlen);
                r->stptr[n->stlen] = '\0';
                if ((n->flags & WSTRCUR) != 0) {
                        r->wstlen = n->wstlen;
-                       emalloc(r->wstptr, wchar_t *, sizeof(wchar_t) * 
(n->wstlen + 2), "r_dupnode");
+                       emalloc(r->wstptr, wchar_t *, sizeof(wchar_t) * 
(n->wstlen + 1), "r_dupnode");
                        memcpy(r->wstptr, n->wstptr, n->wstlen * 
sizeof(wchar_t));
                        r->wstptr[n->wstlen] = L'\0';
                        r->flags |= WSTRCUR;
@@ -368,7 +368,7 @@ make_str_node(const char *s, size_t len, int flags)
        if ((flags & ALREADY_MALLOCED) != 0)
                r->stptr = (char *) s;
        else {
-               emalloc(r->stptr, char *, len + 2, "make_str_node");
+               emalloc(r->stptr, char *, len + 1, "make_str_node");
                memcpy(r->stptr, s, len);
        }
        r->stptr[len] = '\0';
@@ -672,7 +672,7 @@ str2wstr(NODE *n, size_t **ptr)
         * realloc the wide string down in size.
         */
 
-       emalloc(n->wstptr, wchar_t *, sizeof(wchar_t) * (n->stlen + 2), 
"str2wstr");
+       emalloc(n->wstptr, wchar_t *, sizeof(wchar_t) * (n->stlen + 1), 
"str2wstr");
        wsp = n->wstptr;
 
        /*
@@ -746,7 +746,7 @@ str2wstr(NODE *n, size_t **ptr)
        n->flags |= WSTRCUR;
 #define ARBITRARY_AMOUNT_TO_GIVE_BACK 100
        if (n->stlen - n->wstlen > ARBITRARY_AMOUNT_TO_GIVE_BACK)
-               erealloc(n->wstptr, wchar_t *, sizeof(wchar_t) * (n->wstlen + 
2), "str2wstr");
+               erealloc(n->wstptr, wchar_t *, sizeof(wchar_t) * (n->wstlen + 
1), "str2wstr");
 
        return n;
 }
@@ -773,7 +773,7 @@ wstr2str(NODE *n)
        memset(& mbs, 0, sizeof(mbs));
 
        length = n->wstlen;
-       emalloc(newval, char *, (length * gawk_mb_cur_max) + 2, "wstr2str");
+       emalloc(newval, char *, (length * gawk_mb_cur_max) + 1, "wstr2str");
 
        wp = n->wstptr;
        for (cp = newval; length > 0; length--) {
diff --git a/re.c b/re.c
index edb5bc4..98baf5c 100644
--- a/re.c
+++ b/re.c
@@ -75,10 +75,10 @@ make_regexp(const char *s, size_t len, bool ignorecase, 
bool dfa, bool canfatal)
         * from that. 
         */
        if (buf == NULL) {
-               emalloc(buf, char *, len + 2, "make_regexp");
+               emalloc(buf, char *, len + 1, "make_regexp");
                buflen = len;
        } else if (len > buflen) {
-               erealloc(buf, char *, len + 2, "make_regexp");
+               erealloc(buf, char *, len + 1, "make_regexp");
                buflen = len;
        }
        dest = buf;

-----------------------------------------------------------------------


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]