diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-12-14 20:38:14 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-12-14 20:38:14 +0200 |
commit | c55956b6a10d0a4d0b151c1be976dc9c344c1103 (patch) | |
tree | 8711c2b5a501af116782f470fa5c0ec9e18dbabf | |
parent | b6ac928a53d146233741fc5f7fe1cac66de27303 (diff) | |
download | egawk-c55956b6a10d0a4d0b151c1be976dc9c344c1103.tar.gz egawk-c55956b6a10d0a4d0b151c1be976dc9c344c1103.tar.bz2 egawk-c55956b6a10d0a4d0b151c1be976dc9c344c1103.zip |
More fixes to stop allocating an extra byte.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | awkgram.c | 2 | ||||
-rw-r--r-- | awkgram.y | 2 | ||||
-rw-r--r-- | builtin.c | 7 | ||||
-rw-r--r-- | command.c | 10 | ||||
-rw-r--r-- | command.y | 10 | ||||
-rw-r--r-- | debug.c | 12 | ||||
-rw-r--r-- | field.c | 2 | ||||
-rw-r--r-- | io.c | 10 | ||||
-rw-r--r-- | profile.c | 6 |
10 files changed, 40 insertions, 31 deletions
@@ -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. @@ -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; @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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"); @@ -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"); } @@ -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) @@ -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) { |