Fix some misuses of strncat().

This commit is contained in:
Tom Lane 2006-09-27 16:19:42 +00:00
parent 9ba4065312
commit 1d45168f4b
3 changed files with 14 additions and 12 deletions

View File

@ -17,7 +17,7 @@
*
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.20 2006/06/06 22:41:09 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.21 2006/09/27 16:19:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -213,7 +213,7 @@ show_pgxs(bool all)
if (all)
printf("PGXS = ");
get_pkglib_path(mypath, path);
strncat(path, "/pgxs/src/makefiles/pgxs.mk", MAXPGPATH - 1);
strncat(path, "/pgxs/src/makefiles/pgxs.mk", MAXPGPATH - 1 - strlen(path));
cleanup_path(path);
printf("%s\n", path);
}

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.15 2006/05/31 20:58:09 tgl Exp $ */
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.16 2006/09/27 16:19:42 tgl Exp $ */
/******************************************************************************
These are user-defined functions that can be bound to a Postgres backend
@ -85,13 +85,14 @@ copytext(text *t)
text *
concat_text(text *arg1, text *arg2)
{
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
int32 arg1_size = VARSIZE(arg1) - VARHDRSZ;
int32 arg2_size = VARSIZE(arg2) - VARHDRSZ;
int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
memset((void *) new_text, 0, new_text_size);
VARATT_SIZEP(new_text) = new_text_size;
strncpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1) - VARHDRSZ);
strncat(VARDATA(new_text), VARDATA(arg2), VARSIZE(arg2) - VARHDRSZ);
memcpy(VARDATA(new_text), VARDATA(arg1), arg1_size);
memcpy(VARDATA(new_text) + arg1_size, VARDATA(arg2), arg2_size);
return new_text;
}

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/tutorial/funcs_new.c,v 1.11 2006/07/14 14:52:27 momjian Exp $ */
/* $PostgreSQL: pgsql/src/tutorial/funcs_new.c,v 1.12 2006/09/27 16:19:42 tgl Exp $ */
/******************************************************************************
These are user-defined functions that can be bound to a Postgres backend
@ -101,13 +101,14 @@ concat_text(PG_FUNCTION_ARGS)
{
text *arg1 = PG_GETARG_TEXT_P(0);
text *arg2 = PG_GETARG_TEXT_P(1);
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
int32 arg1_size = VARSIZE(arg1) - VARHDRSZ;
int32 arg2_size = VARSIZE(arg2) - VARHDRSZ;
int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
memset((void *) new_text, 0, new_text_size);
VARATT_SIZEP(new_text) = new_text_size;
strncpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1) - VARHDRSZ);
strncat(VARDATA(new_text), VARDATA(arg2), VARSIZE(arg2) - VARHDRSZ);
memcpy(VARDATA(new_text), VARDATA(arg1), arg1_size);
memcpy(VARDATA(new_text) + arg1_size, VARDATA(arg2), arg2_size);
PG_RETURN_TEXT_P(new_text);
}