From cf0a731f592b7165cb050c3fd014daa7f31d71d1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 9 Oct 2016 09:54:21 -0700 Subject: Bugfix: wrong memset size in args_cat_zap. * args.c (args_copy): Use from->arg and from->fill in calculating the memcpy size. It doesn't matter in this function because the to and from are the same; however, this may be the origin of the copy and paste error that led to args_cat_zap problem. (args_copy_zap): Similar change to args_copy: be consistent in using the from side expressions. (args_cat_zap): Bugfix: the total size of the to arguments was used to zap the from side. This writes zeros past the end of the from arguments. Fixing by calculating the size in one place and using the calculated size. --- args.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/args.c b/args.c index d8da977a..7c62baee 100644 --- a/args.c +++ b/args.c @@ -76,23 +76,24 @@ struct args *args_copy(struct args *to, struct args *from) { to->fill = from->fill; to->list = from->list; - memcpy(to->arg, from->arg, sizeof *to->arg * to->fill); + memcpy(to->arg, from->arg, sizeof *from->arg * from->fill); return to; } struct args *args_copy_zap(struct args *to, struct args *from) { args_copy(to, from); - memset(from->arg, 0, sizeof *to->arg * to->fill); + memset(from->arg, 0, sizeof *from->arg * from->fill); return to; } struct args *args_cat_zap(struct args *to, struct args *from) { + size_t size = sizeof *from->arg * from->fill; to->list = from->list; - memcpy(to->arg + to->fill, from->arg, sizeof *from->arg * from->fill); + memcpy(to->arg + to->fill, from->arg, size); to->fill += from->fill; - memset(from->arg, 0, sizeof *to->arg * to->fill); + memset(from->arg, 0, size); return to; } -- cgit v1.2.3