>From 9f212e1cdaaee50607b7c577747fed35c571dab0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 18 Dec 2019 16:02:54 -0800 Subject: [PATCH] Fix memcpy issue found by -fsanitize=undefined * field.c (set_record): Don't memcpy (databuf, NULL, 0), as the C standard says the resulting behavior is undefined. --- ChangeLog | 6 ++++++ field.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e9a543e0..25344e9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-12-18 Paul Eggert + + Fix memcpy issue found by -fsanitize=undefined + * field.c (set_record): Don't memcpy (databuf, NULL, 0), + as the C standard says the resulting behavior is undefined. + 2019-11-21 Arnold D. Robbins * config.rpath: Update from GNULIB. diff --git a/field.c b/field.c index 8c7fe18e..28891c85 100644 --- a/field.c +++ b/field.c @@ -288,7 +288,9 @@ set_record(const char *buf, int cnt, const awk_fieldwidth_info_t *fw) memset(databuf, '\0', databuf_size); } /* copy the data */ - memcpy(databuf, buf, cnt); + if (cnt != 0) { + memcpy(databuf, buf, cnt); + } /* * Add terminating '\0' so that C library routines -- 2.23.0