From c92f7e258ee579abd0f95183598edf250d351b2c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 27 Sep 2006 18:40:10 +0000 Subject: Replace strncpy with strlcpy in selected places that seem possibly relevant to performance. (A wholesale effort to get rid of strncpy should be undertaken sometime, but not during beta.) This commit also fixes dynahash.c to correctly truncate overlength string keys for hashtables, so that its callers don't have to anymore. --- src/backend/utils/error/elog.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/backend/utils/error/elog.c') diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index e46d16fa55d..2aff7f790aa 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -42,7 +42,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.173 2006/07/14 14:52:25 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.174 2006/09/27 18:40:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1225,6 +1225,7 @@ write_syslog(int level, const char *line) while (len > 0) { char buf[PG_SYSLOG_LIMIT + 1]; + const char *nlpos; int buflen; int i; @@ -1236,12 +1237,15 @@ write_syslog(int level, const char *line) continue; } - strncpy(buf, line, PG_SYSLOG_LIMIT); - buf[PG_SYSLOG_LIMIT] = '\0'; - if (strchr(buf, '\n') != NULL) - *strchr(buf, '\n') = '\0'; - - buflen = strlen(buf); + /* copy one line, or as much as will fit, to buf */ + nlpos = strchr(line, '\n'); + if (nlpos != NULL) + buflen = nlpos - line; + else + buflen = len; + buflen = Min(buflen, PG_SYSLOG_LIMIT); + memcpy(buf, line, buflen); + buf[buflen] = '\0'; /* trim to multibyte letter boundary */ buflen = pg_mbcliplen(buf, buflen, buflen); -- cgit v1.2.3