diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | awkgram.c | 16 | ||||
-rw-r--r-- | awkgram.y | 16 | ||||
-rw-r--r-- | debug.c | 10 | ||||
-rw-r--r-- | helpers/ChangeLog | 4 | ||||
-rw-r--r-- | helpers/testdfa.c | 21 | ||||
-rw-r--r-- | io.c | 2 | ||||
-rw-r--r-- | old-extension/ChangeLog | 4 | ||||
-rw-r--r-- | old-extension/bindarr.c | 2 | ||||
-rw-r--r-- | profile.c | 5 |
10 files changed, 38 insertions, 51 deletions
@@ -1,3 +1,12 @@ +2015-04-09 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * awkgram.y (yyerror): Rationalize buffer size computations. Remove + old valgrind workarounds. + * debug.c (gprintf): Rationalize buffer size computations. + (serialize_subscript): Ditto. + * io.c (iop_finish): Rationalize buffer size computations. + * profile.c (pp_string): Correct space allocation computation. + 2015-04-08 John E. Malmberg <wb8tyw@qsl.net> * custom.h: VMS shares some code paths with ZOS_USS in @@ -4516,7 +4516,6 @@ yyerror(const char *m, ...) char *buf; int count; static char end_of_file_line[] = "(END OF FILE)"; - char save; print_included_from(); @@ -4544,24 +4543,15 @@ yyerror(const char *m, ...) bp = thisline + strlen(thisline); } - /* - * Saving and restoring *bp keeps valgrind happy, - * since the guts of glibc uses strlen, even though - * we're passing an explict precision. Sigh. - * - * 8/2003: We may not need this anymore. - */ - save = *bp; - *bp = '\0'; - msg("%.*s", (int) (bp - thisline), thisline); - *bp = save; va_start(args, m); if (mesg == NULL) mesg = m; - count = (bp - thisline) + strlen(mesg) + 1 + 1; + count = strlen(mesg) + 1; + if (lexptr != NULL) + count += (lexeme - thisline) + 2; emalloc(buf, char *, count, "yyerror"); bp = buf; @@ -2178,7 +2178,6 @@ yyerror(const char *m, ...) char *buf; int count; static char end_of_file_line[] = "(END OF FILE)"; - char save; print_included_from(); @@ -2206,24 +2205,15 @@ yyerror(const char *m, ...) bp = thisline + strlen(thisline); } - /* - * Saving and restoring *bp keeps valgrind happy, - * since the guts of glibc uses strlen, even though - * we're passing an explict precision. Sigh. - * - * 8/2003: We may not need this anymore. - */ - save = *bp; - *bp = '\0'; - msg("%.*s", (int) (bp - thisline), thisline); - *bp = save; va_start(args, m); if (mesg == NULL) mesg = m; - count = (bp - thisline) + strlen(mesg) + 1 + 1; + count = strlen(mesg) + 1; + if (lexptr != NULL) + count += (lexeme - thisline) + 2; emalloc(buf, char *, count, "yyerror"); bp = buf; @@ -4205,10 +4205,10 @@ gprintf(FILE *fp, const char *format, ...) #define GPRINTF_BUFSIZ 512 if (buf == NULL) { buflen = GPRINTF_BUFSIZ; - emalloc(buf, char *, (buflen + 1) * sizeof(char), "gprintf"); + emalloc(buf, char *, buflen * sizeof(char), "gprintf"); } else if (buflen - bl < GPRINTF_BUFSIZ/2) { buflen += GPRINTF_BUFSIZ; - erealloc(buf, char *, (buflen + 1) * sizeof(char), "gprintf"); + erealloc(buf, char *, buflen * 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 + 1) * sizeof(char), "gprintf"); + erealloc(buf, char *, buflen * sizeof(char), "gprintf"); } bl = 0; @@ -4267,7 +4267,7 @@ gprintf(FILE *fp, const char *format, ...) static int serialize_subscript(char *buf, int buflen, struct list_item *item) { - int bl = 0, nchar, i; + int bl, nchar, i; NODE *sub; nchar = snprintf(buf, buflen, "%d%c%d%c%s%c%d%c", @@ -4277,7 +4277,7 @@ serialize_subscript(char *buf, int buflen, struct list_item *item) return 0; else if (nchar >= buflen) /* need larger buffer */ return nchar; - bl += nchar; + bl = nchar; for (i = 0; i < item->num_subs; i++) { sub = item->subs[i]; nchar = snprintf(buf + bl, buflen - bl, "%lu%c%s%c", diff --git a/helpers/ChangeLog b/helpers/ChangeLog index 2cb3be44..5a3f2fe3 100644 --- a/helpers/ChangeLog +++ b/helpers/ChangeLog @@ -1,3 +1,7 @@ +2015-04-09 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * testdfa.c (setup_pattern): Rationalize buffer size computations. + 2014-12-18 Arnold D. Robbins <arnold@skeeve.com> * testdfa.c (setup_pattern): Do not waste a byte at the end of a string. diff --git a/helpers/testdfa.c b/helpers/testdfa.c index 092a13d8..2b773467 100644 --- a/helpers/testdfa.c +++ b/helpers/testdfa.c @@ -372,10 +372,10 @@ setup_pattern(const char *pattern, size_t *len) { size_t is_multibyte = 0; int c, c2; - size_t buflen = 0; + size_t buflen; mbstate_t mbs; bool has_anchor = false; - char *buf = NULL; + char *buf; char *dest; const char *src, *end; @@ -391,21 +391,12 @@ setup_pattern(const char *pattern, size_t *len) * escaped characters translated, and generate the regex * from that. */ + buf = (char *) malloc(*len + 1); if (buf == NULL) { - 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 + 1); - if (buf == NULL) { - fprintf(stderr, "%s: realloc failed\n", __func__); - exit(EXIT_FAILURE); - } - buflen = *len; + fprintf(stderr, "%s: malloc failed\n", __func__); + exit(EXIT_FAILURE); } + buflen = *len; dest = buf; while (src < end) { @@ -3164,7 +3164,7 @@ iop_finish(IOBUF *iop) lintwarn(_("data file `%s' is empty"), iop->public.name); iop->errcode = errno = 0; iop->count = iop->scanoff = 0; - emalloc(iop->buf, char *, iop->size += 2, "iop_finish"); + emalloc(iop->buf, char *, iop->size += 1, "iop_finish"); iop->off = iop->buf; iop->dataend = NULL; iop->end = iop->buf + iop->size; diff --git a/old-extension/ChangeLog b/old-extension/ChangeLog index 51f44db4..dad5c794 100644 --- a/old-extension/ChangeLog +++ b/old-extension/ChangeLog @@ -1,3 +1,7 @@ +2015-04-09 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * bindarr.c (do_bind_array): Undo Arnold's change of 2014-12-18. + 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. diff --git a/old-extension/bindarr.c b/old-extension/bindarr.c index 28da389a..41467425 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) + 1, "do_bind_array"); + emalloc(aname, char *, 1 + strlen(symbol->vname) + 1, "do_bind_array"); aname[0] = '~'; /* any illegal character */ strcpy(& aname[1], symbol->vname); td = make_array(); @@ -1371,10 +1371,9 @@ pp_string(const char *in_str, size_t len, int delim) *obufout++ = '\\'; *obufout++ = delim; } else if (*str == '\0') { - chksize(4); - *obufout++ = '\\'; *obufout++ = '0'; + chksize(2); /* need 2 more chars for this case */ *obufout++ = '0'; *obufout++ = '0'; } else if ((cp = strchr(escapes, *str)) != NULL) { @@ -1384,7 +1383,7 @@ pp_string(const char *in_str, size_t len, int delim) /* NB: Deliberate use of lower-case versions. */ } else if (isascii(*str) && isprint(*str)) { *obufout++ = *str; - ofre += 1; + ofre += 1; /* used 1 less than expected */ } else { size_t len; |