diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-09-27 18:40:10 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-09-27 18:40:10 +0000 |
commit | c92f7e258ee579abd0f95183598edf250d351b2c (patch) | |
tree | 10c6b377a74c61b71ece70cfd3cb209795bf1051 /src/backend/utils/error/elog.c | |
parent | 996b203e621bc76985ff0156b4f2ef720944b41b (diff) | |
download | postgresql-c92f7e258ee579abd0f95183598edf250d351b2c.tar.gz postgresql-c92f7e258ee579abd0f95183598edf250d351b2c.zip |
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.
Diffstat (limited to 'src/backend/utils/error/elog.c')
-rw-r--r-- | src/backend/utils/error/elog.c | 18 |
1 files changed, 11 insertions, 7 deletions
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); |