From 4310da6075fb20b819bec6c064f44690e07b49b1 Mon Sep 17 00:00:00 2001 From: John McNamara Date: Wed, 22 Aug 2018 20:52:12 +0100 Subject: [PATCH] Fix for gcc 8.2 warnings. Replace strncat with memcpy to placate gcc 8.2. Also fix issue in tempfileplus. Issue #192. --- src/xmlwriter.c | 14 +++++++------- third_party/tmpfileplus/tmpfileplus.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/xmlwriter.c b/src/xmlwriter.c index 3b70dcd0..ad5e05d7 100644 --- a/src/xmlwriter.c +++ b/src/xmlwriter.c @@ -153,19 +153,19 @@ _escape_attributes(struct xml_attribute *attribute) while (*p_attr) { switch (*p_attr) { case '&': - strncat(p_encoded, LXW_AMP, sizeof(LXW_AMP) - 1); + memcpy(p_encoded, LXW_AMP, sizeof(LXW_AMP) - 1); p_encoded += sizeof(LXW_AMP) - 1; break; case '<': - strncat(p_encoded, LXW_LT, sizeof(LXW_LT) - 1); + memcpy(p_encoded, LXW_LT, sizeof(LXW_LT) - 1); p_encoded += sizeof(LXW_LT) - 1; break; case '>': - strncat(p_encoded, LXW_GT, sizeof(LXW_GT) - 1); + memcpy(p_encoded, LXW_GT, sizeof(LXW_GT) - 1); p_encoded += sizeof(LXW_GT) - 1; break; case '"': - strncat(p_encoded, LXW_QUOT, sizeof(LXW_QUOT) - 1); + memcpy(p_encoded, LXW_QUOT, sizeof(LXW_QUOT) - 1); p_encoded += sizeof(LXW_QUOT) - 1; break; default: @@ -195,15 +195,15 @@ lxw_escape_data(const char *data) while (*data) { switch (*data) { case '&': - strncat(p_encoded, LXW_AMP, sizeof(LXW_AMP) - 1); + memcpy(p_encoded, LXW_AMP, sizeof(LXW_AMP) - 1); p_encoded += sizeof(LXW_AMP) - 1; break; case '<': - strncat(p_encoded, LXW_LT, sizeof(LXW_LT) - 1); + memcpy(p_encoded, LXW_LT, sizeof(LXW_LT) - 1); p_encoded += sizeof(LXW_LT) - 1; break; case '>': - strncat(p_encoded, LXW_GT, sizeof(LXW_GT) - 1); + memcpy(p_encoded, LXW_GT, sizeof(LXW_GT) - 1); p_encoded += sizeof(LXW_GT) - 1; break; default: diff --git a/third_party/tmpfileplus/tmpfileplus.c b/third_party/tmpfileplus/tmpfileplus.c index e1ff7c7b..83d3d9f8 100644 --- a/third_party/tmpfileplus/tmpfileplus.c +++ b/third_party/tmpfileplus/tmpfileplus.c @@ -169,7 +169,7 @@ static char *getenv_save(const char *varname, char *buf, size_t bufsize) buf[0] = '\0'; if (ptr) { - strncpy(buf, ptr, bufsize); + strncpy(buf, ptr, bufsize-1); buf[bufsize-1] = '\0'; return buf; }