summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog27
-rw-r--r--array.c2
-rw-r--r--awkgram.c4
-rw-r--r--awkgram.y4
-rw-r--r--builtin.c13
-rw-r--r--command.c10
-rw-r--r--command.y10
-rw-r--r--debug.c12
-rw-r--r--eval.c4
-rw-r--r--extension/ChangeLog8
-rw-r--r--extension/readfile.c4
-rw-r--r--extension/rwarray.c4
-rw-r--r--extension/rwarray0.c4
-rw-r--r--field.c4
-rw-r--r--gawkapi.h2
-rw-r--r--helpers/ChangeLog4
-rw-r--r--helpers/testdfa.c4
-rw-r--r--interpret.h7
-rw-r--r--io.c9
-rw-r--r--node.c14
-rw-r--r--old-extension/ChangeLog5
-rw-r--r--old-extension/bindarr.c2
-rw-r--r--old-extension/fileop.c2
-rw-r--r--profile.c4
-rw-r--r--re.c4
25 files changed, 106 insertions, 61 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a395564..79e0f1fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -326,6 +326,33 @@
* profile.c (pprint): Be sure to set ip2 in all paths
through the code. Thanks to GCC 4.9 for the warning.
+2014-12-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * builtin.c (do_sub): Do not waste a byte at the end of a string.
+
+2014-12-14 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awkgram.y (yyerror): Do not waste a byte at the end of a string.
+ * builtin.c (do_match): Ditto.
+ * command.y (append_statement): Ditto.
+ * debug.c (gprintf, serialize): Ditto.
+ * field.c (set_FIELDWIDTHS): Ditto.
+ * io.c.c (grow_iop_buffer): Ditto.
+ * profile.c (pp_string, pp_group3): Ditto.
+
+2014-12-14 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * 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-20 Arnold D. Robbins <arnold@skeeve.com>
Enable non-fatal output on per-file or global basis,
diff --git a/array.c b/array.c
index f7993624..59428ba2 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 67c8feae..02c6e41b 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -3399,7 +3399,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';
@@ -4561,7 +4561,7 @@ yyerror(const char *m, ...)
if (mesg == NULL)
mesg = m;
- count = (bp - thisline) + strlen(mesg) + 2 + 1;
+ count = (bp - thisline) + strlen(mesg) + 1 + 1;
emalloc(buf, char *, count, "yyerror");
bp = buf;
diff --git a/awkgram.y b/awkgram.y
index e04c2c65..d723f510 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1443,7 +1443,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';
@@ -2223,7 +2223,7 @@ yyerror(const char *m, ...)
if (mesg == NULL)
mesg = m;
- count = (bp - thisline) + strlen(mesg) + 2 + 1;
+ count = (bp - thisline) + strlen(mesg) + 1 + 1;
emalloc(buf, char *, count, "yyerror");
bp = buf;
diff --git a/builtin.c b/builtin.c
index b70176dc..38a5646b 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1847,7 +1847,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);
@@ -2577,7 +2577,7 @@ do_match(int nargs)
sprintf(buff, "%d", ii);
ilen = strlen(buff);
- amt = ilen + subseplen + strlen("length") + 2;
+ amt = ilen + subseplen + strlen("length") + 1;
if (oldamt == 0) {
emalloc(buf, char *, amt, "do_match");
@@ -2897,11 +2897,10 @@ set_how_many:
lastmatchnonzero = false;
- /* guesstimate how much room to allocate; +2 forces > 0 */
- buflen = textlen + (ampersands + 1) * repllen + 2;
- emalloc(buf, char *, buflen + 2, "do_sub");
+ /* guesstimate how much room to allocate; +1 forces > 0 */
+ buflen = textlen + (ampersands + 1) * repllen + 1;
+ emalloc(buf, char *, buflen + 1, "do_sub");
buf[buflen] = '\0';
- buf[buflen + 1] = '\0';
bp = buf;
for (current = 1;; current++) {
@@ -3029,7 +3028,7 @@ set_how_many:
}
sofar = bp - buf;
if (buflen - sofar - textlen - 1) {
- buflen = sofar + textlen + 2;
+ buflen = sofar + textlen + 1;
erealloc(buf, char *, buflen, "do_sub");
bp = buf + sofar;
}
diff --git a/command.c b/command.c
index 04d5e5f3..b23b21c5 100644
--- a/command.c
+++ b/command.c
@@ -2515,7 +2515,7 @@ append_statement(CMDARG *stmt_list, char *stmt)
len += strlen(a->a_string) + 1; /* 1 for ',' */
len += EVALSIZE;
- emalloc(s, char *, (len + 2) * sizeof(char), "append_statement");
+ emalloc(s, char *, (len + 1) * sizeof(char), "append_statement");
arg = mk_cmdarg(D_string);
arg->a_string = s;
arg->a_count = len; /* kludge */
@@ -2542,7 +2542,7 @@ append_statement(CMDARG *stmt_list, char *stmt)
ssize = stmt_list->a_count;
if (len > ssize - slen) {
ssize = slen + len + EVALSIZE;
- erealloc(s, char *, (ssize + 2) * sizeof(char), "append_statement");
+ erealloc(s, char *, (ssize + 1) * sizeof(char), "append_statement");
stmt_list->a_string = s;
stmt_list->a_count = ssize;
}
@@ -2554,7 +2554,7 @@ append_statement(CMDARG *stmt_list, char *stmt)
}
if (stmt == end_EVAL)
- erealloc(stmt_list->a_string, char *, slen + 2, "append_statement");
+ erealloc(stmt_list->a_string, char *, slen + 1, "append_statement");
return stmt_list;
#undef EVALSIZE
@@ -2921,7 +2921,7 @@ again:
bool esc_seen = false;
toklen = lexend - lexptr;
- emalloc(str, char *, toklen + 2, "yylex");
+ emalloc(str, char *, toklen + 1, "yylex");
p = str;
while ((c = *++lexptr) != '"') {
@@ -3100,7 +3100,7 @@ concat_args(CMDARG *arg, int count)
arg = arg->next;
}
- emalloc(str, char *, len + 2, "concat_args");
+ emalloc(str, char *, len + 1, "concat_args");
n = tmp[0];
memcpy(str, n->stptr, n->stlen);
p = str + n->stlen;
diff --git a/command.y b/command.y
index 08893743..bd5b4870 100644
--- a/command.y
+++ b/command.y
@@ -764,7 +764,7 @@ append_statement(CMDARG *stmt_list, char *stmt)
len += strlen(a->a_string) + 1; /* 1 for ',' */
len += EVALSIZE;
- emalloc(s, char *, (len + 2) * sizeof(char), "append_statement");
+ emalloc(s, char *, (len + 1) * sizeof(char), "append_statement");
arg = mk_cmdarg(D_string);
arg->a_string = s;
arg->a_count = len; /* kludge */
@@ -791,7 +791,7 @@ append_statement(CMDARG *stmt_list, char *stmt)
ssize = stmt_list->a_count;
if (len > ssize - slen) {
ssize = slen + len + EVALSIZE;
- erealloc(s, char *, (ssize + 2) * sizeof(char), "append_statement");
+ erealloc(s, char *, (ssize + 1) * sizeof(char), "append_statement");
stmt_list->a_string = s;
stmt_list->a_count = ssize;
}
@@ -803,7 +803,7 @@ append_statement(CMDARG *stmt_list, char *stmt)
}
if (stmt == end_EVAL)
- erealloc(stmt_list->a_string, char *, slen + 2, "append_statement");
+ erealloc(stmt_list->a_string, char *, slen + 1, "append_statement");
return stmt_list;
#undef EVALSIZE
@@ -1170,7 +1170,7 @@ again:
bool esc_seen = false;
toklen = lexend - lexptr;
- emalloc(str, char *, toklen + 2, "yylex");
+ emalloc(str, char *, toklen + 1, "yylex");
p = str;
while ((c = *++lexptr) != '"') {
@@ -1349,7 +1349,7 @@ concat_args(CMDARG *arg, int count)
arg = arg->next;
}
- emalloc(str, char *, len + 2, "concat_args");
+ emalloc(str, char *, len + 1, "concat_args");
n = tmp[0];
memcpy(str, n->stptr, n->stlen);
p = str + n->stlen;
diff --git a/debug.c b/debug.c
index 58012b72..c2f11355 100644
--- a/debug.c
+++ b/debug.c
@@ -4205,10 +4205,10 @@ gprintf(FILE *fp, const char *format, ...)
#define GPRINTF_BUFSIZ 512
if (buf == NULL) {
buflen = GPRINTF_BUFSIZ;
- emalloc(buf, char *, (buflen + 2) * sizeof(char), "gprintf");
+ emalloc(buf, char *, (buflen + 1) * sizeof(char), "gprintf");
} else if (buflen - bl < GPRINTF_BUFSIZ/2) {
buflen += GPRINTF_BUFSIZ;
- erealloc(buf, char *, (buflen + 2) * sizeof(char), "gprintf");
+ erealloc(buf, char *, (buflen + 1) * sizeof(char), "gprintf");
}
#undef GPRINTF_BUFSIZ
@@ -4227,7 +4227,7 @@ gprintf(FILE *fp, const char *format, ...)
/* enlarge buffer, and try again */
buflen *= 2;
- erealloc(buf, char *, (buflen + 2) * sizeof(char), "gprintf");
+ erealloc(buf, char *, (buflen + 1) * sizeof(char), "gprintf");
}
bl = 0;
@@ -4356,7 +4356,7 @@ serialize(int type)
if (buf == NULL) { /* first time */
buflen = SERIALIZE_BUFSIZ;
- emalloc(buf, char *, buflen + 2, "serialize");
+ emalloc(buf, char *, buflen + 1, "serialize");
}
bl = 0;
@@ -4365,7 +4365,7 @@ serialize(int type)
if (buflen - bl < SERIALIZE_BUFSIZ/2) {
enlarge_buffer:
buflen *= 2;
- erealloc(buf, char *, buflen + 2, "serialize");
+ erealloc(buf, char *, buflen + 1, "serialize");
}
#undef SERIALIZE_BUFSIZ
@@ -4466,7 +4466,7 @@ enlarge_buffer:
}
if (nchar > 0) { /* non-empty commands list */
- nchar += (strlen("commands ") + 20 + strlen("end") + 2); /* 20 for cnum (an int) */
+ nchar += (strlen("commands ") + 20 + strlen("end") + 1); /* 20 for cnum (an int) */
if (nchar > buflen - bl) {
buflen = bl + nchar;
erealloc(buf, char *, buflen + 3, "serialize");
diff --git a/eval.c b/eval.c
index c63dd170..18df2d01 100644
--- a/eval.c
+++ b/eval.c
@@ -827,9 +827,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 5d1651fd..9348d745 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -38,6 +38,7 @@
* testext.c (var_test): Adjust for PROCINFO now being there.
+
2015-01-06 Andrew J. Schorr <aschorr@telemetry-investments.com>
* testext.c (test_deferred): New function to help with testing
@@ -77,6 +78,13 @@
(errno_la_SOURCES, errno_la_LDFLAGS, errno_la_LIBADD): Remove.
(EXTRA_DIST): Remove errlist.h.
+2014-12-14 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * 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 <arnold@skeeve.com>
* inplace.c (do_inplace_begin): Jump through hoops to silence
diff --git a/extension/readfile.c b/extension/readfile.c
index d4b4aef9..7673589f 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 aa05a0d5..5bead973 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 e2de3cf5..ec3663cc 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 6a7c6b1d..13a5db6f 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++) {
@@ -1138,7 +1138,7 @@ set_FIELDWIDTHS()
FIELDWIDTHS[0] = 0;
for (i = 1; ; i++) {
unsigned long int tmp;
- if (i + 2 >= fw_alloc) {
+ if (i + 1 >= fw_alloc) {
fw_alloc *= 2;
erealloc(FIELDWIDTHS, int *, fw_alloc * sizeof(int), "set_FIELDWIDTHS");
}
diff --git a/gawkapi.h b/gawkapi.h
index 3604e906..c5bb1ea9 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -827,7 +827,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/helpers/ChangeLog b/helpers/ChangeLog
index a5bbafb1..2cb3be44 100644
--- a/helpers/ChangeLog
+++ b/helpers/ChangeLog
@@ -1,3 +1,7 @@
+2014-12-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testdfa.c (setup_pattern): Do not waste a byte at the end of a string.
+
2014-09-04 Arnold D. Robbins <arnold@skeeve.com>
* chlistref.awk: New file. Finds @ref{} to non-chapters.
diff --git a/helpers/testdfa.c b/helpers/testdfa.c
index 25a229a2..092a13d8 100644
--- a/helpers/testdfa.c
+++ b/helpers/testdfa.c
@@ -392,14 +392,14 @@ setup_pattern(const char *pattern, size_t *len)
* from that.
*/
if (buf == NULL) {
- buf = (char *) malloc(*len + 2);
+ buf = (char *) malloc(*len + 1);
if (buf == NULL) {
fprintf(stderr, "%s: malloc failed\n", __func__);
exit(EXIT_FAILURE);
}
buflen = *len;
} else if (*len > buflen) {
- buf = (char *) realloc(buf, *len + 2);
+ buf = (char *) realloc(buf, *len + 1);
if (buf == NULL) {
fprintf(stderr, "%s: realloc failed\n", __func__);
exit(EXIT_FAILURE);
diff --git a/interpret.h b/interpret.h
index a11268de..7b9079c0 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/io.c b/io.c
index cf9dd943..835030c1 100644
--- a/io.c
+++ b/io.c
@@ -2683,6 +2683,7 @@ init_awkpath(path_info *pi)
end++;
len = end - start;
if (len > 0) {
+ /* +2 is correct here; leave room for / */
emalloc(p, char *, len + 2, "init_awkpath");
memcpy(p, start, len);
@@ -3169,10 +3170,10 @@ grow_iop_buffer(IOBUF *iop)
size_t newsize;
/*
- * Lop off original extra two bytes, double the size,
- * add them back.
+ * Lop off original extra byte, double the size,
+ * add it back.
*/
- newsize = ((iop->size - 2) * 2) + 2;
+ newsize = ((iop->size - 1) * 2) + 1;
/* Check for overflow */
if (newsize <= iop->size)
@@ -3180,7 +3181,7 @@ grow_iop_buffer(IOBUF *iop)
/* Make sure there's room for a disk block */
if (newsize - valid < iop->readsize)
- newsize += iop->readsize + 2;
+ newsize += iop->readsize + 1;
/* Check for overflow, again */
if (newsize <= iop->size)
diff --git a/node.c b/node.c
index 507d0650..869e4cbc 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/old-extension/ChangeLog b/old-extension/ChangeLog
index 55c8d31d..51f44db4 100644
--- a/old-extension/ChangeLog
+++ b/old-extension/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * bindarr.c (do_bind_array): Do not waste a byte at the end of a string.
+ * fileop.c (do_fread): Ditto.
+
2014-01-07 Arnold D. Robbins <arnold@skeeve.com>
* dbarray.awk: Use full name for lib to load in extenstion() call.
diff --git a/old-extension/bindarr.c b/old-extension/bindarr.c
index 60959903..28da389a 100644
--- a/old-extension/bindarr.c
+++ b/old-extension/bindarr.c
@@ -235,7 +235,7 @@ do_bind_array(int nargs)
}
/* copy the array -- this is passed as the second argument to the functions */
- emalloc(aname, char *, strlen(t->vname) + 2, "do_bind_array");
+ emalloc(aname, char *, strlen(t->vname) + 1, "do_bind_array");
aname[0] = '~'; /* any illegal character */
strcpy(& aname[1], symbol->vname);
td = make_array();
diff --git a/old-extension/fileop.c b/old-extension/fileop.c
index 86f62576..d76a7ded 100644
--- a/old-extension/fileop.c
+++ b/old-extension/fileop.c
@@ -55,7 +55,7 @@ do_fread(int nargs)
force_number(arg);
rlen = get_number_ui(arg);
- emalloc(rbuf, char *, rlen + 2, "do_fread");
+ emalloc(rbuf, char *, rlen + 1, "do_fread");
if ((count = fread(rbuf, 1, rlen, f->fp)) < rlen) {
if (! feof(f->fp))
update_ERRNO_int(errno);
diff --git a/profile.c b/profile.c
index 3e9ef783..ddbf8ed1 100644
--- a/profile.c
+++ b/profile.c
@@ -1339,7 +1339,7 @@ pp_string(const char *in_str, size_t len, int delim)
osiz *= 2; \
} ofre -= (l)
- osiz = len + 3 + 2; /* initial size; 3 for delim + terminating null */
+ osiz = len + 3 + 1; /* initial size; 3 for delim + terminating null */
emalloc(obuf, char *, osiz, "pp_string");
obufout = obuf;
ofre = osiz - 1;
@@ -1587,7 +1587,7 @@ pp_group3(const char *s1, const char *s2, const char *s3)
len1 = strlen(s1);
len2 = strlen(s2);
len3 = strlen(s3);
- l = len1 + len2 + len3 + 2;
+ l = len1 + len2 + len3 + 1;
emalloc(str, char *, l, "pp_group3");
s = str;
if (len1 > 0) {
diff --git a/re.c b/re.c
index 7abb9430..a46208ef 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;