summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-07-22 07:17:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-07-22 07:17:44 +0200
commitd29196d9e2a00cd556f9452259147e02692b6bb2 (patch)
treea7fcc91dc1a0d25874fb28196b31d0fd90a1688b
parent5ff07837303b8aa513f536ca8221e8463973c014 (diff)
Get rid of str[n]cpy() calls
-rw-r--r--genx.c15
-rw-r--r--makefile2
2 files changed, 11 insertions, 6 deletions
diff --git a/genx.c b/genx.c
index 685c54a..b2b999f 100644
--- a/genx.c
+++ b/genx.c
@@ -179,10 +179,13 @@ static void deallocate(genxWriter w, void * data)
static utf8 copy(genxWriter w, constUtf8 from)
{
utf8 temp;
+ size_t sl = strlen((const char *) from);
- if ((temp = (utf8) allocate(w, strlen((const char *) from) + 1)) == NULL)
+ if ((temp = (utf8) allocate(w, sl + 1)) == NULL)
return NULL;
- strcpy((char *) temp, (const char *) from);
+
+ memcpy(temp, from, sl);
+ temp[sl] = 0;
return temp;
}
@@ -203,7 +206,7 @@ static genxStatus growCollector(genxWriter w, collector * c, size_t size)
if ((newSpace = (utf8) allocate(w, c->space)) == NULL)
return GENX_ALLOC_FAILED;
- strncpy((char *) newSpace, (const char *) c->buf, c->used);
+ memcpy(newSpace, c->buf, c->used);
newSpace[c->used] = 0;
deallocate(w, c->buf);
c->buf = newSpace;
@@ -227,11 +230,13 @@ static genxStatus collectString(genxWriter w, collector * c, constUtf8 string)
if ((w->status = growCollector(w, c, sl)) != GENX_SUCCESS)
return GENX_ALLOC_FAILED;
- strcpy((char *) c->buf, (const char *) string);
+ memcpy(c->buf, string, sl);
+ c->buf[sl] = 0;
return GENX_SUCCESS;
}
-#define collectPiece(w,c,d,size) {if (((c)->used+(size))>=(c)->space){if (((w)->status=growCollector(w,c,(c)->used+(size)))!=GENX_SUCCESS) return (w)->status;}strncpy((char *)(c)->buf+(c)->used,d,size);(c)->used+=size;}
+/* Note: does not add the trailing '\0' (done by endCollect() call). */
+#define collectPiece(w,c,d,size) {if (((c)->used+(size))>=(c)->space){if (((w)->status=growCollector(w,c,(c)->used+(size)))!=GENX_SUCCESS) return (w)->status;}memcpy((char *)(c)->buf+(c)->used,d,size);(c)->used+=size;}
/*******************************
* private list utilities
diff --git a/makefile b/makefile
index ab06a68..0625c7a 100644
--- a/makefile
+++ b/makefile
@@ -3,7 +3,7 @@
src := genx.c char-props.c
CC := gcc
-CFLAGS := -W -Wall
+CFLAGS := -Wall -Wextra -Werror
# Compile.
#