aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-12-14 20:38:14 +0200
committerArnold D. Robbins <arnold@skeeve.com>2014-12-14 20:38:14 +0200
commitc55956b6a10d0a4d0b151c1be976dc9c344c1103 (patch)
tree8711c2b5a501af116782f470fa5c0ec9e18dbabf
parentb6ac928a53d146233741fc5f7fe1cac66de27303 (diff)
downloadegawk-c55956b6a10d0a4d0b151c1be976dc9c344c1103.tar.gz
egawk-c55956b6a10d0a4d0b151c1be976dc9c344c1103.tar.bz2
egawk-c55956b6a10d0a4d0b151c1be976dc9c344c1103.zip
More fixes to stop allocating an extra byte.
-rw-r--r--ChangeLog10
-rw-r--r--awkgram.c2
-rw-r--r--awkgram.y2
-rw-r--r--builtin.c7
-rw-r--r--command.c10
-rw-r--r--command.y10
-rw-r--r--debug.c12
-rw-r--r--field.c2
-rw-r--r--io.c10
-rw-r--r--profile.c6
10 files changed, 40 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index c54a1774..f890a70d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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 (init_awkpath, grow_iop_buffer): Ditto.
+ * profile.c (pp_string, pp_concat, 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.
diff --git a/awkgram.c b/awkgram.c
index 4715290d..827c09ba 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4548,7 +4548,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 f6a396a5..b476ef5b 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2210,7 +2210,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 838ab899..067b410e 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2554,7 +2554,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");
@@ -2876,9 +2876,8 @@ set_how_many:
/* guesstimate how much room to allocate; +2 forces > 0 */
buflen = textlen + (ampersands + 1) * repllen + 2;
- emalloc(buf, char *, buflen + 2, "do_sub");
+ emalloc(buf, char *, buflen + 1, "do_sub");
buf[buflen] = '\0';
- buf[buflen + 1] = '\0';
bp = buf;
for (current = 1;; current++) {
@@ -3006,7 +3005,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 2d4bc814..5304cd64 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/field.c b/field.c
index c23f0b10..13a5db6f 100644
--- a/field.c
+++ b/field.c
@@ -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/io.c b/io.c
index 1d15d887..86dfc135 100644
--- a/io.c
+++ b/io.c
@@ -2554,7 +2554,7 @@ init_awkpath(path_info *pi)
end++;
len = end - start;
if (len > 0) {
- emalloc(p, char *, len + 2, "init_awkpath");
+ emalloc(p, char *, len + 1, "init_awkpath");
memcpy(p, start, len);
/* add directory punctuation if necessary */
@@ -3040,10 +3040,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)
@@ -3051,7 +3051,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/profile.c b/profile.c
index ad879a3c..45eb562c 100644
--- a/profile.c
+++ b/profile.c
@@ -1337,7 +1337,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;
@@ -1505,7 +1505,7 @@ pp_concat(int nargs)
len = -delimlen;
for (i = nargs; i >= 1; i--) {
r = pp_args[i] = pp_pop();
- len += r->pp_len + delimlen + 2;
+ len += r->pp_len + delimlen + 1;
}
emalloc(str, char *, len + 1, "pp_concat");
@@ -1571,7 +1571,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) {