diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-09 09:54:21 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-09 09:54:21 -0700 |
commit | cf0a731f592b7165cb050c3fd014daa7f31d71d1 (patch) | |
tree | 9f6aa83e8892a58aeaeecf156e7f814c227c39ab | |
parent | 5942e1316ef3647b063180eb04b13319838172d2 (diff) | |
download | txr-cf0a731f592b7165cb050c3fd014daa7f31d71d1.tar.gz txr-cf0a731f592b7165cb050c3fd014daa7f31d71d1.tar.bz2 txr-cf0a731f592b7165cb050c3fd014daa7f31d71d1.zip |
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.
-rw-r--r-- | args.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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; } |