Skip site navigation (1) Skip section navigation (2)

Small misc tidyup patch

From: Matthew Kirkwood <matthew(at)hairy(dot)beasts(dot)org>
To: pgsql-patches(at)postgresql(dot)org
Subject: Small misc tidyup patch
Date: 2001-02-24 16:15:03
Message-ID: Pine.LNX.4.10.10102241557590.13430-100000@sphinx.mythic-beasts.com (view raw or flat)
Thread:
Lists: pgsql-patches
Hi,

Here's a silly patch, which does the following:

 * One unnecessary sprintf becomes strcpy.
 * unsigned long is 64 bit on alpha.  Extra
   paranoia.
 * Minor optimisation to strdup.

Matthew.


diff -ruN postgresql-7.1beta5-clean/src/backend/access/transam/xid.c postgresql-7.1beta5/src/backend/access/transam/xid.c
--- postgresql-7.1beta5-clean/src/backend/access/transam/xid.c	Mon Jan 29 02:53:36 2001
+++ postgresql-7.1beta5/src/backend/access/transam/xid.c	Sat Feb 24 15:16:36 2001
@@ -49,10 +49,10 @@
 xidout(PG_FUNCTION_ARGS)
 {
 	TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
-	/* maximum 32 bit unsigned integer representation takes 10 chars */
-	char	   *representation = palloc(11);
+	/* maximum 64 bit unsigned long representation takes 20 chars */
+	char	   *representation = palloc(21);
 
-	snprintf(representation, 11, "%lu", (unsigned long) transactionId);
+	snprintf(representation, 21, "%lu", (unsigned long) transactionId);
 
 	PG_RETURN_CSTRING(representation);
 }
diff -ruN postgresql-7.1beta5-clean/src/backend/access/transam/xlogutils.c postgresql-7.1beta5/src/backend/access/transam/xlogutils.c
--- postgresql-7.1beta5-clean/src/backend/access/transam/xlogutils.c	Fri Feb 23 18:12:00 2001
+++ postgresql-7.1beta5/src/backend/access/transam/xlogutils.c	Sat Feb 24 15:16:36 2001
@@ -166,7 +166,7 @@
 	logRelation->rd_rel = (Form_pg_class) malloc(sizeof(FormData_pg_class));
 	memset(logRelation->rd_rel, 0, sizeof(FormData_pg_class));
 
-	sprintf(RelationGetPhysicalRelationName(logRelation), "pg_log");
+	strcpy(RelationGetPhysicalRelationName(logRelation), "pg_log");
 	logRelation->rd_node.tblNode = InvalidOid;
 	logRelation->rd_node.relNode = RelOid_pg_log;
 	logRelation->rd_fd = -1;
diff -ruN postgresql-7.1beta5-clean/src/utils/strdup.c postgresql-7.1beta5/src/utils/strdup.c
--- postgresql-7.1beta5-clean/src/utils/strdup.c	Mon Jan 29 02:53:58 2001
+++ postgresql-7.1beta5/src/utils/strdup.c	Sat Feb 24 15:16:36 2001
@@ -20,7 +20,11 @@
 strdup(char const * string)
 {
 	char	   *nstr;
+	size_t		len;
 
-	nstr = strcpy((char *) malloc(strlen(string) + 1), string);
+	len = strlen(string) + 1;
+	nstr = malloc(len);
+	if (nstr)
+		memcpy(nstr, string, len);
 	return nstr;
 }


pgsql-patches by date

Next:From: Tom LaneDate: 2001-02-24 16:41:06
Subject: Re: A patch for xlog.c
Previous:From: Matthew KirkwoodDate: 2001-02-24 15:49:37
Subject: A patch for xlog.c

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group