diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index 8517010e5ed28a364afe785598f1a1917842a8c5..23ee8f1dada416d790e82cb15b53e40f6f12d30f 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -779,7 +779,7 @@ querytree(PG_FUNCTION_ARGS)
 
 		res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ);
 		VARATT_SIZEP(res) = nrm.cur - nrm.buf + VARHDRSZ;
-		strncpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
+		memcpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
 	}
 	pfree(q);
 
diff --git a/contrib/tsearch2/query.c b/contrib/tsearch2/query.c
index b832deb22e841624b02aaad7893e10a621bbdcbd..902ee22fe545201c085867c82393e4c57dc5ec2b 100644
--- a/contrib/tsearch2/query.c
+++ b/contrib/tsearch2/query.c
@@ -928,7 +928,7 @@ tsquerytree(PG_FUNCTION_ARGS)
 
 		res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ);
 		VARATT_SIZEP(res) = nrm.cur - nrm.buf + VARHDRSZ;
-		strncpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
+		memcpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
 		pfree(q);
 	}