diff options
-rw-r--r-- | usr.bin/hexdump/parse.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c index 1231a15..ef19278 100644 --- a/usr.bin/hexdump/parse.c +++ b/usr.bin/hexdump/parse.c @@ -213,6 +213,7 @@ rewrite(FS *fs) unsigned char *p1, *p2, *fmtp; char savech, cs[3]; int nconv, prec; + size_t len; nextpr = NULL; prec = 0; @@ -394,10 +395,10 @@ isint2: switch(fu->bcnt) { */ savech = *p2; p1[0] = '\0'; - if ((pr->fmt = calloc(1, strlen(fmtp) + 2)) == NULL) + len = strlen(fmtp) + strlen(cs) + 1; + if ((pr->fmt = calloc(1, len)) == NULL) err(1, NULL); - (void)strcpy(pr->fmt, fmtp); - (void)strcat(pr->fmt, cs); + snprintf(pr->fmt, len, "%s%s", fmtp, cs); *p2 = savech; pr->cchar = pr->fmt + (p1 - fmtp); fmtp = p2; |