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/commands/prepare.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'src/backend/commands/prepare.c') diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index eccce9d10d..46824a48e5 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -10,7 +10,7 @@ * Copyright (c) 2002-2006, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.64 2006/09/07 22:52:00 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.65 2006/09/27 18:40:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -314,7 +314,6 @@ StorePreparedStatement(const char *stmt_name, MemoryContext oldcxt, entrycxt; char *qstring; - char key[NAMEDATALEN]; bool found; /* Initialize the hash table, if necessary */ @@ -322,10 +321,7 @@ StorePreparedStatement(const char *stmt_name, InitQueryHashTable(); /* Check for pre-existing entry of same name */ - /* See notes in FetchPreparedStatement */ - StrNCpy(key, stmt_name, sizeof(key)); - - hash_search(prepared_queries, key, HASH_FIND, &found); + hash_search(prepared_queries, stmt_name, HASH_FIND, &found); if (found) ereport(ERROR, @@ -355,7 +351,7 @@ StorePreparedStatement(const char *stmt_name, /* Now we can add entry to hash table */ entry = (PreparedStatement *) hash_search(prepared_queries, - key, + stmt_name, HASH_ENTER, &found); @@ -384,7 +380,6 @@ StorePreparedStatement(const char *stmt_name, PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError) { - char key[NAMEDATALEN]; PreparedStatement *entry; /* @@ -392,19 +387,10 @@ FetchPreparedStatement(const char *stmt_name, bool throwError) * anything, therefore it couldn't possibly store our plan. */ if (prepared_queries) - { - /* - * We can't just use the statement name as supplied by the user: the - * hash package is picky enough that it needs to be NUL-padded out to - * the appropriate length to work correctly. - */ - StrNCpy(key, stmt_name, sizeof(key)); - entry = (PreparedStatement *) hash_search(prepared_queries, - key, + stmt_name, HASH_FIND, NULL); - } else entry = NULL; -- cgit v1.2.1