1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-05 23:56:58 +03:00

Fix pgproc names over 15 chars in output. Add strNcpy() function. remove some (void) casts that are unnecessary.

This commit is contained in:
Bruce Momjian 1997-08-12 20:16:25 +00:00
parent 4b851b1cfc
commit edb58721b8
44 changed files with 163 additions and 192 deletions

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.3 1996/11/06 08:21:42 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.4 1997/08/12 20:15:13 momjian Exp $
* *
* NOTES * NOTES
* At the point the version is defined, 2 physical relations are created * At the point the version is defined, 2 physical relations are created
@ -106,12 +106,12 @@ DefineVersion(char *name, char *fromRelname, char *date)
if (date == NULL) { if (date == NULL) {
/* no time ranges */ /* no time ranges */
bname = fromRelname; bname = fromRelname;
(void) strcpy(saved_basename, (char *) bname); strcpy(saved_basename, (char *) bname);
*saved_snapshot = (char)NULL; *saved_snapshot = (char)NULL;
} else { } else {
/* version is a snapshot */ /* version is a snapshot */
bname = fromRelname; bname = fromRelname;
(void) strcpy(saved_basename, (char *) bname); strcpy(saved_basename, (char *) bname);
sprintf(saved_snapshot, "['%s']", date); sprintf(saved_snapshot, "['%s']", date);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.14 1997/08/03 02:34:34 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.15 1997/08/12 20:15:08 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -456,8 +456,7 @@ Async_Listen(char *relname, int pid)
* to unlisten prior to dying. * to unlisten prior to dying.
*/ */
relnamei = malloc(NAMEDATALEN); /* persists to process exit */ relnamei = malloc(NAMEDATALEN); /* persists to process exit */
strncpy(relnamei, relname, NAMEDATALEN); strNcpy(relnamei, relname, NAMEDATALEN-1);
relnamei[NAMEDATALEN-1] = '\0';
on_exitpg(Async_UnlistenOnExit, (caddr_t) relnamei); on_exitpg(Async_UnlistenOnExit, (caddr_t) relnamei);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.8 1997/08/03 02:34:53 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.9 1997/08/12 20:15:10 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -61,8 +61,7 @@ DefineRelation(CreateStmt *stmt)
if ( strlen(stmt->relname) >= NAMEDATALEN) if ( strlen(stmt->relname) >= NAMEDATALEN)
elog(WARN, "the relation name %s is >= %d characters long", stmt->relname, elog(WARN, "the relation name %s is >= %d characters long", stmt->relname,
NAMEDATALEN); NAMEDATALEN);
strncpy(relname,stmt->relname,NAMEDATALEN); /* make full length for copy */ strNcpy(relname,stmt->relname,NAMEDATALEN-1); /* make full length for copy */
relname[NAMEDATALEN-1] = '\0';
/* ---------------- /* ----------------
* Handle parameters * Handle parameters

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/recipe.c,v 1.5 1996/11/06 08:21:37 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/recipe.c,v 1.6 1997/08/12 20:15:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1149,8 +1149,7 @@ replaceTeeScans(Plan* plan, Query* parsetree, TeeInfo *teeInfo)
if ((strlen(rte->refname) < 4) || if ((strlen(rte->refname) < 4) ||
(strcmp (rte->relname, rte->refname) != 0)) (strcmp (rte->relname, rte->refname) != 0))
continue; continue;
strncpy(prefix,rte->refname,4); strNcpy(prefix,rte->refname,4);
prefix[4] = '\0';
if (strcmp(prefix,"tee_") == 0) { if (strcmp(prefix,"tee_") == 0) {
/* okay, we found a tee node entry in the range table */ /* okay, we found a tee node entry in the range table */

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.4 1996/11/10 02:59:42 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.5 1997/08/12 20:15:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -235,8 +235,8 @@ renamerel(char oldrelname[], char newrelname[])
} }
/* rename the directory first, so if this fails the rename's not done */ /* rename the directory first, so if this fails the rename's not done */
(void) strcpy(oldpath, relpath(oldrelname)); strcpy(oldpath, relpath(oldrelname));
(void) strcpy(newpath, relpath(newrelname)); strcpy(newpath, relpath(newrelname));
if (rename(oldpath, newpath) < 0) if (rename(oldpath, newpath) < 0)
elog(WARN, "renamerel: unable to rename file: %m"); elog(WARN, "renamerel: unable to rename file: %m");

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/lib/stringinfo.c,v 1.2 1996/11/06 08:27:16 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/lib/stringinfo.c,v 1.3 1997/08/12 20:15:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -111,6 +111,6 @@ appendStringInfo(StringInfo str, char *buffer)
* NOTE: this is a text string (i.e. printable characters) * NOTE: this is a text string (i.e. printable characters)
* so 'strcat' will do the job (no need to use 'bcopy' et all...) * so 'strcat' will do the job (no need to use 'bcopy' et all...)
*/ */
(void) strcat(str->data, buffer); strcat(str->data, buffer);
str->len += buflen; str->len += buflen;
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.11 1997/03/25 00:54:15 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.12 1997/08/12 20:15:17 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -302,10 +302,10 @@ pg_krb5_recvauth(int sock,
* easy, we construct our own name and parse it. See note on * easy, we construct our own name and parse it. See note on
* canonicalization above. * canonicalization above.
*/ */
(void) strcpy(servbuf, PG_KRB_SRVNAM); strcpy(servbuf, PG_KRB_SRVNAM);
*(hostp = servbuf + (sizeof(PG_KRB_SRVNAM) - 1)) = '/'; *(hostp = servbuf + (sizeof(PG_KRB_SRVNAM) - 1)) = '/';
if (gethostname(++hostp, MAXHOSTNAMELEN) < 0) if (gethostname(++hostp, MAXHOSTNAMELEN) < 0)
(void) strcpy(hostp, "localhost"); strcpy(hostp, "localhost");
if (hostp = strchr(hostp, '.')) if (hostp = strchr(hostp, '.'))
*hostp = '\0'; *hostp = '\0';
if (code = krb5_parse_name(servbuf, &server)) { if (code = krb5_parse_name(servbuf, &server)) {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.10 1997/06/10 13:01:32 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.11 1997/08/12 20:15:18 momjian Exp $
* *
* NOTES * NOTES
* This should be moved to a more appropriate place. It is here * This should be moved to a more appropriate place. It is here
@ -257,8 +257,7 @@ lo_import(text *filename)
/* /*
* open the file to be read in * open the file to be read in
*/ */
strncpy(fnamebuf, VARDATA(filename), VARSIZE(filename) - VARHDRSZ); strNcpy(fnamebuf, VARDATA(filename), VARSIZE(filename) - VARHDRSZ);
fnamebuf[VARSIZE(filename) - VARHDRSZ] = '\0';
fd = open(fnamebuf, O_RDONLY, 0666); fd = open(fnamebuf, O_RDONLY, 0666);
if (fd < 0) { /* error */ if (fd < 0) { /* error */
elog(WARN, "be_lo_import: can't open unix file\"%s\"\n", elog(WARN, "be_lo_import: can't open unix file\"%s\"\n",
@ -325,8 +324,7 @@ lo_export(Oid lobjId, text *filename)
* open the file to be written to * open the file to be written to
*/ */
oumask = umask((mode_t) 0); oumask = umask((mode_t) 0);
strncpy(fnamebuf, VARDATA(filename), VARSIZE(filename) - VARHDRSZ); strNcpy(fnamebuf, VARDATA(filename), VARSIZE(filename) - VARHDRSZ);
fnamebuf[VARSIZE(filename) - VARHDRSZ] = '\0';
fd = open(fnamebuf, O_CREAT|O_WRONLY, 0666); fd = open(fnamebuf, O_CREAT|O_WRONLY, 0666);
(void) umask(oumask); (void) umask(oumask);
if (fd < 0) { /* error */ if (fd < 0) { /* error */

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.2 1996/11/06 08:48:26 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.3 1997/08/12 20:15:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -223,7 +223,7 @@ strmake(char *str, int len)
if (len <= 0) len = strlen(str); if (len <= 0) len = strlen(str);
newstr = (char *) palloc((unsigned) len+1); newstr = (char *) palloc((unsigned) len+1);
(void) strncpy(newstr, str, len); strNcpy(newstr, str, len);
newstr[len] = (char) 0; newstr[len] = (char) 0;
return newstr; return newstr;
} }

View File

@ -80,8 +80,7 @@ verify_password(char *user, char *password, Port *port,
/* kill the newline */ /* kill the newline */
test_pw[strlen(test_pw)-1] = '\0'; test_pw[strlen(test_pw)-1] = '\0';
strncpy(salt, test_pw, 2); strNcpy(salt, test_pw, 2);
salt[2] = '\0';
if(strcmp(user, test_user) == 0) { if(strcmp(user, test_user) == 0) {
/* we're outta here one way or the other. */ /* we're outta here one way or the other. */

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.4 1996/11/06 08:48:28 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.5 1997/08/12 20:15:22 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -144,7 +144,7 @@ PQpnames(char **pnames, int rule_p)
for (i = 0; i < portals_array_size; ++i) { for (i = 0; i < portals_array_size; ++i) {
if (portals[i] && portals[i]->portal) { if (portals[i] && portals[i]->portal) {
if (!rule_p || portals[i]->portal->rule_p) { if (!rule_p || portals[i]->portal->rule_p) {
(void) strncpy(pnames[cur_pname], portals[i]->name, PortalNameLength); strncpy(pnames[cur_pname], portals[i]->name, PortalNameLength);
++cur_pname; ++cur_pname;
} }
} }
@ -710,7 +710,7 @@ PQappendNotify(char *relname, int pid)
pqNotifyList = DLNewList(); pqNotifyList = DLNewList();
p = (PQNotifyList*)pbuf_alloc(sizeof(PQNotifyList)); p = (PQNotifyList*)pbuf_alloc(sizeof(PQNotifyList));
strncpy(p->relname, relname, NAMEDATALEN); strNcpy(p->relname, relname, NAMEDATALEN-1);
p->be_pid = pid; p->be_pid = pid;
p->valid = 1; p->valid = 1;
DLAddTail(pqNotifyList, DLNewElem(p)); DLAddTail(pqNotifyList, DLNewElem(p));

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.3 1996/11/06 08:48:29 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.4 1997/08/12 20:15:23 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -377,8 +377,7 @@ void
pbuf_setportalinfo(PortalEntry *entry, char *pname) pbuf_setportalinfo(PortalEntry *entry, char *pname)
{ {
if (entry) if (entry)
strncpy(entry->name, pname, PortalNameLength-1); strNcpy(entry->name, pname, PortalNameLength-1);
entry->name[PortalNameLength-1] = '\0';
} }
/* -------------------------------- /* --------------------------------

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.17 1997/07/28 00:54:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.18 1997/08/12 20:15:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -113,7 +113,7 @@ pq_getc(FILE* fin)
void void
pq_gettty(char *tp) pq_gettty(char *tp)
{ {
(void) strncpy(tp, ttyname(0), 19); strncpy(tp, ttyname(0), 19);
} }
/* -------------------------------- /* --------------------------------
@ -585,8 +585,8 @@ StreamServerPort(char *hostName, short portName, int *fdP)
"FATAL: StreamServerPort: bind() failed: errno=%d\n", "FATAL: StreamServerPort: bind() failed: errno=%d\n",
errno); errno);
pqdebug("%s", PQerrormsg); pqdebug("%s", PQerrormsg);
(void) strcat(PQerrormsg, "\tIs another postmaster already running on that port?\n"); strcat(PQerrormsg, "\tIs another postmaster already running on that port?\n");
(void) strcat(PQerrormsg, "\tIf not, wait a few seconds and retry.\n"); strcat(PQerrormsg, "\tIf not, wait a few seconds and retry.\n");
fputs(PQerrormsg, stderr); fputs(PQerrormsg, stderr);
return(STATUS_ERROR); return(STATUS_ERROR);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.4 1997/08/03 02:35:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.5 1997/08/12 20:15:27 momjian Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
@ -349,15 +349,13 @@ print_plan_recursive (Plan* p, Query *parsetree, int indentLevel, char* label)
if (IsA(p,Scan) || IsA(p,SeqScan)) { if (IsA(p,Scan) || IsA(p,SeqScan)) {
RangeTblEntry *rte; RangeTblEntry *rte;
rte = rt_fetch(((Scan*)p)->scanrelid, parsetree->rtable); rte = rt_fetch(((Scan*)p)->scanrelid, parsetree->rtable);
strncpy(extraInfo, rte->relname, NAMEDATALEN); strNcpy(extraInfo, rte->relname, NAMEDATALEN-1);
extraInfo[NAMEDATALEN-1] = '\0';
} else } else
if (IsA(p,IndexScan)) { if (IsA(p,IndexScan)) {
strncpy(extraInfo, strNcpy(extraInfo,
((RangeTblEntry*)(nth(((IndexScan*)p)->scan.scanrelid - 1, ((RangeTblEntry*)(nth(((IndexScan*)p)->scan.scanrelid - 1,
parsetree->rtable)))->relname, parsetree->rtable)))->relname,
NAMEDATALEN); NAMEDATALEN-1);
extraInfo[NAMEDATALEN-1] = '\0';
} else } else
extraInfo[0] = '\0'; extraInfo[0] = '\0';
if (extraInfo[0] != '\0') if (extraInfo[0] != '\0')

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.5 1997/05/12 07:17:23 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.6 1997/08/12 20:15:28 momjian Exp $
* *
* NOTES * NOTES
* Most of the read functions for plan nodes are tested. (In fact, they * Most of the read functions for plan nodes are tested. (In fact, they
@ -87,8 +87,7 @@ _readQuery()
else { else {
NotifyStmt *n = makeNode(NotifyStmt); NotifyStmt *n = makeNode(NotifyStmt);
n->relname = palloc(length + 1); n->relname = palloc(length + 1);
strncpy(n->relname,token,length); strNcpy(n->relname,token,length);
n->relname[length] = '\0';
local_node->utilityStmt = (Node*)n; local_node->utilityStmt = (Node*)n;
} }
@ -106,8 +105,7 @@ _readQuery()
local_node->uniqueFlag = NULL; local_node->uniqueFlag = NULL;
else { else {
local_node->uniqueFlag = palloc(length + 1); local_node->uniqueFlag = palloc(length + 1);
strncpy(local_node->uniqueFlag,token,length); strNcpy(local_node->uniqueFlag,token,length);
local_node->uniqueFlag[length] = '\0';
} }
token = lsptok(NULL, &length); /* skip :targetlist */ token = lsptok(NULL, &length); /* skip :targetlist */
@ -1033,8 +1031,7 @@ _readAggreg()
token = lsptok(NULL, &length); /* eat :aggname */ token = lsptok(NULL, &length); /* eat :aggname */
token = lsptok(NULL, &length); /* get aggname */ token = lsptok(NULL, &length); /* get aggname */
local_node->aggname = (char*) palloc (length + 1); local_node->aggname = (char*) palloc (length + 1);
memset (local_node->aggname, 0, length + 1); strNcpy (local_node->aggname, token, length);
strncpy (local_node->aggname, token, length);
token = lsptok(NULL, &length); /* eat :basetype */ token = lsptok(NULL, &length); /* eat :basetype */
token = lsptok(NULL, &length); /* get basetype */ token = lsptok(NULL, &length); /* get basetype */

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.30 1997/08/03 02:35:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.31 1997/08/12 20:15:31 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1004,8 +1004,7 @@ makeTargetNames(ParseState *pstate, List *cols)
Ident *id = makeNode(Ident); Ident *id = makeNode(Ident);
id->name = palloc(NAMEDATALEN); id->name = palloc(NAMEDATALEN);
strncpy(id->name, attr[i]->attname.data, NAMEDATALEN); strNcpy(id->name, attr[i]->attname.data, NAMEDATALEN-1);
id->name[NAMEDATALEN-1]='\0';
id->indirection = NIL; id->indirection = NIL;
id->isRel = false; id->isRel = false;
if (tl == NIL) if (tl == NIL)

View File

@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.19 1997/07/24 20:13:01 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.20 1997/08/12 20:15:32 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1488,7 +1488,7 @@ func_error(char *caller, char *funcname, int nargs, Oid *argtypes)
*ptr++ = ' '; *ptr++ = ' ';
} }
if (argtypes[i] != 0) { if (argtypes[i] != 0) {
(void) strcpy(ptr, tname(get_id_type(argtypes[i]))); strcpy(ptr, tname(get_id_type(argtypes[i])));
*(ptr + NAMEDATALEN) = '\0'; *(ptr + NAMEDATALEN) = '\0';
} else } else
strcpy(ptr, "opaque"); strcpy(ptr, "opaque");

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.34 1997/05/22 00:24:07 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.35 1997/08/12 20:15:33 momjian Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
@ -2190,8 +2190,7 @@ opt_id: Id { $$ = $1; }
relation_name: SpecialRuleRelation relation_name: SpecialRuleRelation
{ {
$$ = $1; $$ = $1;
strncpy(saved_relname, $1, NAMEDATALEN); strNcpy(saved_relname, $1, NAMEDATALEN-1);
saved_relname[NAMEDATALEN-1] = '\0';
} }
| Id | Id
{ {
@ -2204,8 +2203,7 @@ relation_name: SpecialRuleRelation
} else { } else {
$$ = $1; $$ = $1;
} }
strncpy(saved_relname, $1, NAMEDATALEN); strNcpy(saved_relname, $1, NAMEDATALEN-1);
saved_relname[NAMEDATALEN-1] = '\0';
} }
; ;

View File

@ -52,7 +52,7 @@ BSD44_derived_dlerror(void)
{ {
static char ret[BUFSIZ]; static char ret[BUFSIZ];
(void) strcpy(ret, error_message); strcpy(ret, error_message);
error_message[0] = 0; error_message[0] = 0;
return((ret[0] == 0) ? (char *) NULL : ret); return((ret[0] == 0) ? (char *) NULL : ret);
} }

View File

@ -466,8 +466,7 @@ static int readExports(ModulePtr mp)
* must copy the first SYMNMLEN chars and make * must copy the first SYMNMLEN chars and make
* sure we have a zero byte at the end. * sure we have a zero byte at the end.
*/ */
strncpy(tmpsym, ls->l_name, SYMNMLEN); strNcpy(tmpsym, ls->l_name, SYMNMLEN);
tmpsym[SYMNMLEN] = '\0';
symname = tmpsym; symname = tmpsym;
} }
ep->name = strdup(symname); ep->name = strdup(symname);

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.49 1997/08/03 02:36:01 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.50 1997/08/12 20:15:42 momjian Exp $
* *
* NOTES * NOTES
* *
@ -241,7 +241,7 @@ PostmasterMain(int argc, char *argv[])
if (!(hostName = getenv("PGHOST"))) { if (!(hostName = getenv("PGHOST"))) {
if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0) if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
(void) strcpy(hostbuf, "localhost"); strcpy(hostbuf, "localhost");
hostName = hostbuf; hostName = hostbuf;
} }
@ -262,8 +262,8 @@ PostmasterMain(int argc, char *argv[])
* were allocated. * were allocated.
*/ */
NBuffers = atol(optarg); NBuffers = atol(optarg);
(void) strcat(ExtraOptions, " -B "); strcat(ExtraOptions, " -B ");
(void) strcat(ExtraOptions, optarg); strcat(ExtraOptions, optarg);
break; break;
case 'b': case 'b':
/* Set the backend executable file to use. */ /* Set the backend executable file to use. */
@ -308,8 +308,8 @@ PostmasterMain(int argc, char *argv[])
* Other options to pass to the backend on the * Other options to pass to the backend on the
* command line -- useful only for debugging. * command line -- useful only for debugging.
*/ */
(void) strcat(ExtraOptions, " "); strcat(ExtraOptions, " ");
(void) strcat(ExtraOptions, optarg); strcat(ExtraOptions, optarg);
break; break;
case 'p': case 'p':
/* Set PGPORT by hand. */ /* Set PGPORT by hand. */
@ -652,8 +652,7 @@ ConnStartup(Port *port, int *status,
msgType = (MsgType) ntohl(port->buf.msgtype); msgType = (MsgType) ntohl(port->buf.msgtype);
(void) strncpy(namebuf, sp.user, NAMEDATALEN); strNcpy(namebuf, sp.user, NAMEDATALEN-1);
namebuf[NAMEDATALEN-1] = '\0';
if (!namebuf[0]) { if (!namebuf[0]) {
strncpy(errormsg, strncpy(errormsg,
"No Postgres username specified in startup packet.", "No Postgres username specified in startup packet.",
@ -1087,8 +1086,7 @@ DoExec(StartupInfo *packet, int portFd)
int ac = 0; int ac = 0;
int i; int i;
(void) strncpy(execbuf, Execfile, MAXPATHLEN); strncpy(execbuf, Execfile, MAXPATHLEN-1);
execbuf[MAXPATHLEN - 1] = '\0';
av[ac++] = execbuf; av[ac++] = execbuf;
/* Tell the backend it is being called from the postmaster */ /* Tell the backend it is being called from the postmaster */
@ -1111,7 +1109,7 @@ DoExec(StartupInfo *packet, int portFd)
/* Pass the requested debugging output file */ /* Pass the requested debugging output file */
if (packet->tty[0]) { if (packet->tty[0]) {
(void) strncpy(ttybuf, packet->tty, ARGV_SIZE); strncpy(ttybuf, packet->tty, ARGV_SIZE);
av[ac++] = "-o"; av[ac++] = "-o";
av[ac++] = ttybuf; av[ac++] = ttybuf;
} }
@ -1125,17 +1123,15 @@ DoExec(StartupInfo *packet, int portFd)
(void) sprintf(portbuf, "-P%d", portFd); (void) sprintf(portbuf, "-P%d", portFd);
av[ac++] = portbuf; av[ac++] = portbuf;
(void) strncpy(argbuf, packet->options, ARGV_SIZE); strNcpy(argbuf, packet->options, ARGV_SIZE);
argbuf[ARGV_SIZE] = '\0'; strncat(argbuf, ExtraOptions, ARGV_SIZE);
(void) strncat(argbuf, ExtraOptions, ARGV_SIZE);
argbuf[(2 * ARGV_SIZE)] = '\0'; argbuf[(2 * ARGV_SIZE)] = '\0';
split_opts(av, &ac, argbuf); split_opts(av, &ac, argbuf);
if (packet->database[0]) if (packet->database[0])
(void) strncpy(dbbuf, packet->database, ARGV_SIZE); strNcpy(dbbuf, packet->database, ARGV_SIZE);
else else
(void) strncpy(dbbuf, packet->user, NAMEDATALEN); strNcpy(dbbuf, packet->user, NAMEDATALEN-1);
dbbuf[ARGV_SIZE] = '\0';
av[ac++] = dbbuf; av[ac++] = dbbuf;
av[ac] = (char *) NULL; av[ac] = (char *) NULL;

View File

@ -1255,7 +1255,7 @@ register char *cp;
return; return;
} }
(void) strcpy(cs->multis + oldend - 1, cp); strcpy(cs->multis + oldend - 1, cp);
cs->multis[cs->smultis - 1] = '\0'; cs->multis[cs->smultis - 1] = '\0';
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.15 1997/08/03 02:36:22 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.16 1997/08/12 20:15:48 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -167,8 +167,7 @@ mdunlink(Relation reln)
** to do this. ** to do this.
*/ */
strncpy(fname, RelationGetRelationName(reln)->data, NAMEDATALEN); strNcpy(fname, RelationGetRelationName(reln)->data, NAMEDATALEN-1);
fname[NAMEDATALEN-1] = '\0';
if (FileNameUnlink(fname) < 0) if (FileNameUnlink(fname) < 0)
return (SM_FAIL); return (SM_FAIL);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.39 1997/08/06 05:38:35 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.40 1997/08/12 20:15:49 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
@ -300,7 +300,7 @@ SocketBackend(char *inBuf, bool multiplexedBackend)
* get input from the frontend * get input from the frontend
* ---------------- * ----------------
*/ */
(void) strcpy(qtype, "?"); strcpy(qtype, "?");
if (pq_getnchar(qtype,0,1) == EOF) { if (pq_getnchar(qtype,0,1) == EOF) {
/* ------------ /* ------------
* when front-end applications quits/dies * when front-end applications quits/dies
@ -865,7 +865,7 @@ PostgresMain(int argc, char *argv[])
or 'localhost' */ or 'localhost' */
if (!(hostName = getenv("PGHOST"))) { if (!(hostName = getenv("PGHOST"))) {
if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0) if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
(void) strcpy(hostbuf, "localhost"); strcpy(hostbuf, "localhost");
hostName = hostbuf; hostName = hostbuf;
} }
@ -1010,7 +1010,7 @@ PostgresMain(int argc, char *argv[])
* o - send output (stdout and stderr) to the given file * o - send output (stdout and stderr) to the given file
* ---------------- * ----------------
*/ */
(void) strncpy(OutputFileName, optarg, MAXPGPATH); strNcpy(OutputFileName, optarg, MAXPGPATH);
break; break;
case 'p': /* started by postmaster */ case 'p': /* started by postmaster */
@ -1292,7 +1292,7 @@ PostgresMain(int argc, char *argv[])
*/ */
if (IsUnderPostmaster == false) { if (IsUnderPostmaster == false) {
puts("\nPOSTGRES backend interactive interface"); puts("\nPOSTGRES backend interactive interface");
puts("$Revision: 1.39 $ $Date: 1997/08/06 05:38:35 $"); puts("$Revision: 1.40 $ $Date: 1997/08/12 20:15:49 $");
} }
/* ---------------- /* ----------------

View File

@ -2,7 +2,7 @@
* Routines for handling of 'SET var TO', 'SHOW var' and 'RESET var' * Routines for handling of 'SET var TO', 'SHOW var' and 'RESET var'
* statements. * statements.
* *
* $Id: variable.c,v 1.12 1997/06/20 17:17:03 thomas Exp $ * $Id: variable.c,v 1.13 1997/08/12 20:15:50 momjian Exp $
* *
*/ */
@ -70,8 +70,7 @@ static const char *get_token(char **tok, char **val, const char *str)
} }
*tok = (char*) PALLOC(len + 1); *tok = (char*) PALLOC(len + 1);
strncpy (*tok, start, len); strNcpy (*tok, start, len);
(*tok)[len] = '\0';
/* skip white spaces */ /* skip white spaces */
while ( isspace(*str)) str++; while ( isspace(*str)) str++;
@ -110,8 +109,7 @@ static const char *get_token(char **tok, char **val, const char *str)
} }
*val = (char*) PALLOC(len + 1); *val = (char*) PALLOC(len + 1);
strncpy (*val, start, len); strNcpy (*val, start, len);
(*val)[len] = '\0';
/* skip white spaces */ /* skip white spaces */
while ( isspace(*str)) str++; while ( isspace(*str)) str++;

View File

@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tioga/Attic/tgRecipe.c,v 1.2 1996/11/03 06:52:45 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/tioga/Attic/tgRecipe.c,v 1.3 1997/08/12 20:15:52 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -100,8 +100,7 @@ first character\n", ARRAY_LEFT_DELIM);
nextlen = endQuote - beginQuote; /* don't subtract one here because we nextlen = endQuote - beginQuote; /* don't subtract one here because we
need the extra character for \0 anyway */ need the extra character for \0 anyway */
word = (char*) malloc(nextlen); word = (char*) malloc(nextlen);
strncpy(word, beginQuote+1, nextlen-1); strNcpy(word, beginQuote+1, nextlen-1);
word[nextlen-1] ='\0';
addArr_TgString(result, (TgString*)&word); addArr_TgString(result, (TgString*)&word);
free (word); free (word);
str = endQuote + 1; str = endQuote + 1;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.11 1997/08/03 02:36:41 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.12 1997/08/12 20:15:54 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -245,17 +245,17 @@ aclitemout(AclItem *aip)
elog(NOTICE, "aclitemout: usesysid %d not found", elog(NOTICE, "aclitemout: usesysid %d not found",
aip->ai_id); aip->ai_id);
(void) strcat(p, tmp); strcat(p, tmp);
pfree(tmp); pfree(tmp);
} else } else
(void) strncat(p, (char *) &((Form_pg_user) strncat(p, (char *) &((Form_pg_user)
GETSTRUCT(htp))->usename, GETSTRUCT(htp))->usename,
sizeof(NameData)); sizeof(NameData));
break; break;
case ACL_IDTYPE_GID: case ACL_IDTYPE_GID:
(void) strcat(p, "group "); strcat(p, "group ");
tmpname = get_groname(aip->ai_id); tmpname = get_groname(aip->ai_id);
(void) strncat(p, tmpname, NAMEDATALEN); strncat(p, tmpname, NAMEDATALEN);
break; break;
case ACL_IDTYPE_WORLD: case ACL_IDTYPE_WORLD:
break; break;

View File

@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.5 1997/06/11 05:17:58 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.6 1997/08/12 20:15:55 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -265,8 +265,7 @@ uint32 char4in(char *s)
if (s == NULL) if (s == NULL)
return(0); return(0);
memset((char *) &res, 0, sizeof(res)); strncpy((char *) &res, s, 4);
(void) strncpy((char *) &res, s, 4);
return(res); return(res);
} }
@ -276,8 +275,7 @@ char *char4out(s)
{ {
char *result = (char *) palloc(5); char *result = (char *) palloc(5);
memset(result, 0, 5); strNcpy(result, (char *) &s, 4);
(void) strncpy(result, (char *) &s, 4);
return(result); return(result);
} }
@ -326,8 +324,7 @@ char *char8in(char *s)
return((char *) NULL); return((char *) NULL);
result = (char *) palloc(8); result = (char *) palloc(8);
memset(result, 0, 8); strncpy(result, s, 8);
(void) strncpy(result, s, 8);
return(result); return(result);
} }
@ -335,12 +332,11 @@ char *char8out(char *s)
{ {
char *result = (char *) palloc(9); char *result = (char *) palloc(9);
memset(result, 0, 9);
if (s == NULL) { if (s == NULL) {
result[0] = '-'; result[0] = '-';
} else { result[1] = '\0';
strncpy(result, s, 8); } else
} strNcpy(result, s, 8);
return(result); return(result);
} }

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.10 1997/07/29 15:54:49 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.11 1997/08/12 20:15:57 momjian Exp $
* *
* NOTES * NOTES
* This code is actually (almost) unused. * This code is actually (almost) unused.
@ -200,7 +200,7 @@ reltime2tm(int32 time, struct tm *tm)
timestring = (char *) palloc(Max(strlen(INVALID_RELTIME_STR), timestring = (char *) palloc(Max(strlen(INVALID_RELTIME_STR),
UNITMAXLEN) + 1); UNITMAXLEN) + 1);
if (timevalue == INVALID_RELTIME) { if (timevalue == INVALID_RELTIME) {
(void) strcpy(timestring,INVALID_RELTIME_STR); strcpy(timestring,INVALID_RELTIME_STR);
return(timestring); return(timestring);
} }
if (timevalue == 0) if (timevalue == 0)
@ -259,19 +259,19 @@ char *tintervalout(TimeInterval interval)
char *i_str, *p; char *i_str, *p;
i_str = (char *) palloc( T_INTERVAL_LEN ); /* ['...' '...'] */ i_str = (char *) palloc( T_INTERVAL_LEN ); /* ['...' '...'] */
(void) strcpy(i_str,"[\""); strcpy(i_str,"[\"");
if (interval->status == T_INTERVAL_INVAL) if (interval->status == T_INTERVAL_INVAL)
(void) strcat(i_str,INVALID_INTERVAL_STR); strcat(i_str,INVALID_INTERVAL_STR);
else { else {
p = nabstimeout(interval->data[0]); p = nabstimeout(interval->data[0]);
(void) strcat(i_str,p); strcat(i_str,p);
pfree(p); pfree(p);
(void) strcat(i_str,"\" \""); strcat(i_str,"\" \"");
p = nabstimeout(interval->data[1]); p = nabstimeout(interval->data[1]);
(void) strcat(i_str,p); strcat(i_str,p);
pfree(p); pfree(p);
} }
(void) strcat(i_str,"\"]\0"); strcat(i_str,"\"]\0");
return(i_str); return(i_str);
} }
@ -963,7 +963,7 @@ timeofday(void)
int len = 0; int len = 0;
gettimeofday(&tp, &tpz); gettimeofday(&tp, &tpz);
(void) strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%d %Y %Z", strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%d %Y %Z",
localtime((time_t *) &tp.tv_sec)); localtime((time_t *) &tp.tv_sec));
sprintf(buf, templ, tp.tv_usec); sprintf(buf, templ, tp.tv_usec);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.7 1997/07/24 20:16:11 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.8 1997/08/12 20:15:58 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -63,8 +63,7 @@ filename_in(char *file)
len = strlen(name); len = strlen(name);
} else { } else {
len = (p - file) - 1; len = (p - file) - 1;
strncpy(name, file+1, len); strNcpy(name, file+1, len);
name[len] = '\0';
} }
/*printf("name: %s\n");*/ /*printf("name: %s\n");*/
if ((pw = getpwnam(name)) == NULL) { if ((pw = getpwnam(name)) == NULL) {
@ -84,8 +83,7 @@ filename_in(char *file)
len = strlen(environment); len = strlen(environment);
} else { } else {
len = (p - file) - 1; len = (p - file) - 1;
strncpy(environment, file+1, len); strNcpy(environment, file+1, len);
environment[len] = '\0';
} }
envirp = getenv(environment); envirp = getenv(environment);
if (envirp) { if (envirp) {

View File

@ -45,8 +45,7 @@ fixedlen_like(char *s, struct varlena* p, int charlen)
/* be sure sterm is null-terminated */ /* be sure sterm is null-terminated */
sterm = (char *) palloc(charlen + 1); sterm = (char *) palloc(charlen + 1);
memset(sterm, 0, charlen + 1); strNcpy(sterm, s, charlen);
strncpy(sterm, s, charlen);
/* p is a text = varlena, not a string so we have to make /* p is a text = varlena, not a string so we have to make
* a string from the vl_data field of the struct. */ * a string from the vl_data field of the struct. */
@ -140,7 +139,7 @@ bool textnlike(struct varlena *s, struct varlena *p)
} }
/* $Revision: 1.4 $ /* $Revision: 1.5 $
** "like.c" A first attempt at a LIKE operator for Postgres95. ** "like.c" A first attempt at a LIKE operator for Postgres95.
** **
** Originally written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. ** Originally written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.28 1997/07/08 22:06:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.29 1997/08/12 20:16:00 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -286,11 +286,11 @@ nabstimeout(AbsoluteTime time)
char zone[MAXDATELEN+1], *tzn = zone; char zone[MAXDATELEN+1], *tzn = zone;
switch (time) { switch (time) {
case EPOCH_ABSTIME: (void) strcpy(buf, EPOCH); break; case EPOCH_ABSTIME: strcpy(buf, EPOCH); break;
case INVALID_ABSTIME: (void) strcpy(buf, INVALID); break; case INVALID_ABSTIME: strcpy(buf, INVALID); break;
case CURRENT_ABSTIME: (void) strcpy(buf, DCURRENT); break; case CURRENT_ABSTIME: strcpy(buf, DCURRENT); break;
case NOEND_ABSTIME: (void) strcpy(buf, LATE); break; case NOEND_ABSTIME: strcpy(buf, LATE); break;
case NOSTART_ABSTIME: (void) strcpy(buf, EARLY); break; case NOSTART_ABSTIME: strcpy(buf, EARLY); break;
default: default:
abstime2tm( time, &tz, tm, tzn); abstime2tm( time, &tz, tm, tzn);
#if DATEDEBUG #if DATEDEBUG

View File

@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.3 1997/08/03 02:36:57 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.4 1997/08/12 20:16:01 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -39,8 +39,7 @@ NameData *namein(char *s)
return(NULL); return(NULL);
result = (NameData*) palloc(NAMEDATALEN); result = (NameData*) palloc(NAMEDATALEN);
/* always keep it null-padded */ /* always keep it null-padded */
(void) strncpy(result->data, s, NAMEDATALEN); strNcpy(result->data, s, NAMEDATALEN-1);
result->data[NAMEDATALEN-1] = '\0';
return(result); return(result);
} }
@ -126,7 +125,7 @@ int namecpy(Name n1, Name n2)
{ {
if (!n1 || !n2) if (!n1 || !n2)
return(-1); return(-1);
(void) strncpy(n1->data, n2->data, NAMEDATALEN); strncpy(n1->data, n2->data, NAMEDATALEN);
return(0); return(0);
} }
@ -145,8 +144,7 @@ namestrcpy(Name name, char *str)
{ {
if (!name || !str) if (!name || !str)
return(-1); return(-1);
(void) strncpy(name->data, str, NAMEDATALEN); strNcpy(name->data, str, NAMEDATALEN-1);
name->data[NAMEDATALEN-1] = '\0';
return(0); return(0);
} }

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.10 1997/04/22 17:47:14 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.11 1997/08/12 20:16:02 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -149,7 +149,7 @@ ftoa(double value, char *ascii, int width, int prec1, char format)
ascii[width] = 0; ascii[width] = 0;
return(0); return(0);
} }
(void) strcpy(ascii, out); strcpy(ascii, out);
return(ret); return(ret);
#else #else
auto int expon; auto int expon;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/oidname.c,v 1.3 1997/08/03 02:37:08 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/oidname.c,v 1.4 1997/08/12 20:16:03 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -35,8 +35,8 @@ oidnamein(char *inStr)
if (*inptr) { if (*inptr) {
oc->id = (Oid) pg_atoi(inStr, sizeof(Oid), ','); oc->id = (Oid) pg_atoi(inStr, sizeof(Oid), ',');
/* copy one less to ensure null-padding */ /* copy one less to ensure null-padding */
strncpy(oc->name.data,++inptr,NAMEDATALEN); ++inptr;
/* namestrcpy(&oc->name, ++inptr); */ strNcpy(oc->name.data,inptr,NAMEDATALEN-1);
}else }else
elog(WARN, "Bad input data for type oidname"); elog(WARN, "Bad input data for type oidname");

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.5 1996/11/10 01:20:44 bryanh Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.6 1997/08/12 20:16:04 momjian Exp $
* *
* Alistair Crooks added the code for the regex caching * Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance * agc - cached the regular expressions used - there's a good chance
@ -166,8 +166,7 @@ fixedlen_regexeq(char *s, struct varlena* p, int charlen, int cflags)
/* be sure sterm is null-terminated */ /* be sure sterm is null-terminated */
sterm = (char *) palloc(charlen + 1); sterm = (char *) palloc(charlen + 1);
memset(sterm, 0, charlen + 1); strNcpy(sterm, s, charlen);
strncpy(sterm, s, charlen);
result = RE_compile_and_execute(p, sterm, cflags); result = RE_compile_and_execute(p, sterm, cflags);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.4 1997/04/27 19:20:16 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.5 1997/08/12 20:16:05 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -122,14 +122,14 @@ char *regprocout(RegProcedure proid)
s = (char *) heap_getattr(proctup, InvalidBuffer, 1, s = (char *) heap_getattr(proctup, InvalidBuffer, 1,
RelationGetTupleDescriptor(proc), &isnull); RelationGetTupleDescriptor(proc), &isnull);
if (!isnull) { if (!isnull) {
strncpy(result, s, 16); strNcpy(result, s, 16);
break; break;
} }
elog(FATAL, "regprocout: null procedure %d", proid); elog(FATAL, "regprocout: null procedure %d", proid);
/*FALLTHROUGH*/ /*FALLTHROUGH*/
case 0: case 0:
memset(result, 0, 16);
result[0] = '-'; result[0] = '-';
result[1] = '\0';
#ifdef EBUG #ifdef EBUG
elog(DEBUG, "regprocout: no such procedure %d", proid); elog(DEBUG, "regprocout: no such procedure %d", proid);
#endif /* defined(EBUG) */ #endif /* defined(EBUG) */

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.7 1997/03/14 23:21:01 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.8 1997/08/12 20:16:07 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -98,8 +98,7 @@ bpcharout(char *s)
} else { } else {
len = *(int32*)s - 4; len = *(int32*)s - 4;
result = (char *) palloc(len+1); result = (char *) palloc(len+1);
strncpy(result, s+4, len); /* these are blank-padded */ strNcpy(result, s+4, len); /* these are blank-padded */
result[len] = '\0';
} }
return(result); return(result);
} }
@ -136,8 +135,7 @@ varcharin(char *s, int dummy, int typlen)
result = (char *) palloc(typlen); result = (char *) palloc(typlen);
*(int32*)result = typlen; *(int32*)result = typlen;
memset(result+4, 0, len); strncpy(result+4, s, len);
(void) strncpy(result+4, s, len);
return(result); return(result);
} }
@ -155,8 +153,7 @@ varcharout(char *s)
} else { } else {
len = *(int32*)s - 4; len = *(int32*)s - 4;
result = (char *) palloc(len+1); result = (char *) palloc(len+1);
memset(result, 0, len+1); strNcpy(result, s+4, len);
strncpy(result, s+4, len);
} }
return(result); return(result);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.7 1997/07/24 20:16:59 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.8 1997/08/12 20:16:09 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -152,7 +152,7 @@ handle_load(char *filename, char *funcname)
* Same files - different paths (ie, symlink or link) * Same files - different paths (ie, symlink or link)
*/ */
if (file_scanner != (DynamicFileList *) NULL) if (file_scanner != (DynamicFileList *) NULL)
(void) strcpy(file_scanner->filename, filename); strcpy(file_scanner->filename, filename);
} }
} else { } else {
@ -175,7 +175,7 @@ handle_load(char *filename, char *funcname)
} }
memset((char *) file_scanner, 0, sizeof(DynamicFileList)); memset((char *) file_scanner, 0, sizeof(DynamicFileList));
(void) strcpy(file_scanner->filename, filename); strcpy(file_scanner->filename, filename);
file_scanner->device = stat_buf.st_dev; file_scanner->device = stat_buf.st_dev;
file_scanner->inode = stat_buf.st_ino; file_scanner->inode = stat_buf.st_ino;
file_scanner->next = (DynamicFileList *) NULL; file_scanner->next = (DynamicFileList *) NULL;

View File

@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.3 1997/02/14 04:18:08 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.4 1997/08/12 20:16:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -167,12 +167,12 @@ FindBackend(char *backend, char *argv0)
if (*argv0 == '/' || !getcwd(buf, MAXPGPATH)) if (*argv0 == '/' || !getcwd(buf, MAXPGPATH))
buf[0] = '\0'; buf[0] = '\0';
else else
(void) strcat(buf, "/"); strcat(buf, "/");
(void) strcat(buf, argv0); strcat(buf, argv0);
p = strrchr(buf, '/'); p = strrchr(buf, '/');
(void) strcpy(++p, "postgres"); strcpy(++p, "postgres");
if (!ValidateBackend(buf)) { if (!ValidateBackend(buf)) {
(void) strncpy(backend, buf, MAXPGPATH); strncpy(backend, buf, MAXPGPATH);
if (DebugLvl) if (DebugLvl)
fprintf(stderr, "FindBackend: found \"%s\" using argv[0]\n", fprintf(stderr, "FindBackend: found \"%s\" using argv[0]\n",
backend); backend);
@ -192,7 +192,7 @@ FindBackend(char *backend, char *argv0)
fprintf(stderr, "FindBackend: searching PATH ...\n"); fprintf(stderr, "FindBackend: searching PATH ...\n");
pathlen = strlen(p); pathlen = strlen(p);
path = malloc(pathlen + 1); path = malloc(pathlen + 1);
(void) strcpy(path, p); strcpy(path, p);
for (startp = path, endp = strchr(path, ':'); for (startp = path, endp = strchr(path, ':');
startp && *startp; startp && *startp;
startp = endp + 1, endp = strchr(startp, ':')) { startp = endp + 1, endp = strchr(startp, ':')) {
@ -202,11 +202,11 @@ FindBackend(char *backend, char *argv0)
*endp = '\0'; *endp = '\0';
if (*startp == '/' || !getcwd(buf, MAXPGPATH)) if (*startp == '/' || !getcwd(buf, MAXPGPATH))
buf[0] = '\0'; buf[0] = '\0';
(void) strcat(buf, startp); strcat(buf, startp);
(void) strcat(buf, "/postgres"); strcat(buf, "/postgres");
switch (ValidateBackend(buf)) { switch (ValidateBackend(buf)) {
case 0: /* found ok */ case 0: /* found ok */
(void) strncpy(backend, buf, MAXPGPATH); strncpy(backend, buf, MAXPGPATH);
if (DebugLvl) if (DebugLvl)
fprintf(stderr, "FindBackend: found \"%s\" using PATH\n", fprintf(stderr, "FindBackend: found \"%s\" using PATH\n",
backend); backend);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.11 1997/08/06 17:11:20 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.12 1997/08/12 20:16:14 momjian Exp $
* *
* NOTES * NOTES
* Sorts the first relation into the second relation. * Sorts the first relation into the second relation.
@ -214,17 +214,17 @@ resetpsort()
*/ */
#define PUTTUP(NODE, TUP, FP) if (1) {\ #define PUTTUP(NODE, TUP, FP) do {\
((Psortstate *)NODE->psortstate)->BytesWritten += (TUP)->t_len; \ ((Psortstate *)NODE->psortstate)->BytesWritten += (TUP)->t_len; \
fwrite((char *)TUP, (TUP)->t_len, 1, FP);} else fwrite((char *)TUP, (TUP)->t_len, 1, FP);} while (0)
#define ENDRUN(FP) fwrite((char *)&shortzero, sizeof (shortzero), 1, FP) #define ENDRUN(FP) fwrite((char *)&shortzero, sizeof (shortzero), 1, FP)
#define GETLEN(LEN, FP) fread((char *)&(LEN), sizeof (shortzero), 1, FP) #define GETLEN(LEN, FP) fread((char *)&(LEN), sizeof (shortzero), 1, FP)
#define ALLOCTUP(LEN) ((HeapTuple)palloc((unsigned)LEN)) #define ALLOCTUP(LEN) ((HeapTuple)palloc((unsigned)LEN))
#define GETTUP(NODE, TUP, LEN, FP) if (1) {\ #define GETTUP(NODE, TUP, LEN, FP) do {\
IncrProcessed(); \ IncrProcessed(); \
((Psortstate *)NODE->psortstate)->BytesRead += (LEN) - sizeof (shortzero); \ ((Psortstate *)NODE->psortstate)->BytesRead += (LEN) - sizeof (shortzero); \
fread((char *)(TUP) + sizeof (shortzero), (LEN) - sizeof (shortzero), 1, FP);} \ fread((char *)(TUP) + sizeof (shortzero), (LEN) - sizeof (shortzero), 1, FP);} \
else while (0)
#define SETTUPLEN(TUP, LEN) (TUP)->t_len = LEN #define SETTUPLEN(TUP, LEN) (TUP)->t_len = LEN
/* /*

View File

@ -7,7 +7,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: c.h,v 1.13 1997/05/17 16:25:57 mergl Exp $ * $Id: c.h,v 1.14 1997/08/12 20:16:17 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -29,7 +29,7 @@
* 5) IsValid macros for system types * 5) IsValid macros for system types
* 6) offsetof, lengthof, endof * 6) offsetof, lengthof, endof
* 7) exception handling definitions, Assert, Trap, etc macros * 7) exception handling definitions, Assert, Trap, etc macros
* 8) Min, Max, Abs macros * 8) Min, Max, Abs, strNcpy macros
* 9) externs * 9) externs
* 10) Berkeley-specific defs * 10) Berkeley-specific defs
* 11) system-specific hacks * 11) system-specific hacks
@ -681,6 +681,14 @@ typedef struct Exception {
*/ */
#define Abs(x) ((x) >= 0 ? (x) : -(x)) #define Abs(x) ((x) >= 0 ? (x) : -(x))
/*
* strNcpy --
* Does string copy, and forces terminating NULL
*/
/* we do this so if the macro is used in an if action, it will work */
#define strNcpy(dest,src,len) do \
{strncpy((dest),(src),(len));*((dest) + (len)) = '\0';} while (0)
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* Section 9: externs * Section 9: externs
* ---------------------------------------------------------------- * ----------------------------------------------------------------

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.7 1997/03/12 21:23:02 scrappy Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.8 1997/08/12 20:16:21 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -273,10 +273,10 @@ krb5_ccache pg_krb5_init(void)
"pg_krb5_init: krb5_cc_default_name failed\n"); "pg_krb5_init: krb5_cc_default_name failed\n");
return((krb5_ccache) NULL); return((krb5_ccache) NULL);
} }
(void) strcpy(tktbuf, defname); strcpy(tktbuf, defname);
if (realm = getenv("PGREALM")) { if (realm = getenv("PGREALM")) {
(void) strcat(tktbuf, "@"); strcat(tktbuf, "@");
(void) strcat(tktbuf, realm); strcat(tktbuf, realm);
} }
if (code = krb5_cc_resolve(tktbuf, &ccache)) { if (code = krb5_cc_resolve(tktbuf, &ccache)) {
@ -374,19 +374,19 @@ pg_krb5_sendauth(const char* PQerrormsg,int sock,
/* /*
* set up server -- canonicalize as described above * set up server -- canonicalize as described above
*/ */
(void) strcpy(servbuf, PG_KRB_SRVNAM); strcpy(servbuf, PG_KRB_SRVNAM);
*(hostp = servbuf + (sizeof(PG_KRB_SRVNAM) - 1)) = '/'; *(hostp = servbuf + (sizeof(PG_KRB_SRVNAM) - 1)) = '/';
if (hostname || *hostname) { if (hostname || *hostname) {
(void) strncpy(++hostp, hostname, MAXHOSTNAMELEN); strncpy(++hostp, hostname, MAXHOSTNAMELEN);
} else { } else {
if (gethostname(++hostp, MAXHOSTNAMELEN) < 0) if (gethostname(++hostp, MAXHOSTNAMELEN) < 0)
(void) strcpy(hostp, "localhost"); strcpy(hostp, "localhost");
} }
if (hostp = strchr(hostp, '.')) if (hostp = strchr(hostp, '.'))
*hostp = '\0'; *hostp = '\0';
if (realm = getenv("PGREALM")) { if (realm = getenv("PGREALM")) {
(void) strcat(servbuf, "@"); strcat(servbuf, "@");
(void) strcat(servbuf, realm); strcat(servbuf, realm);
} }
if (code = krb5_parse_name(servbuf, &server)) { if (code = krb5_parse_name(servbuf, &server)) {
(void) sprintf(PQerrormsg, (void) sprintf(PQerrormsg,
@ -565,7 +565,7 @@ fe_getauthname(char* PQerrormsg)
} }
if(name && (authn = (char *) malloc(strlen(name) + 1))) if(name && (authn = (char *) malloc(strlen(name) + 1)))
(void) strcpy(authn, name); strcpy(authn, name);
return(authn); return(authn);
} }

View File

@ -37,7 +37,7 @@ concat16(char16 *arg1, char16 *arg2)
char16 *new_c16 = (char16 *) palloc(sizeof(char16)); char16 *new_c16 = (char16 *) palloc(sizeof(char16));
memset(new_c16, 0, sizeof(char16)); memset(new_c16, 0, sizeof(char16));
(void) strncpy((char*)new_c16, (char*)arg1, 16); strncpy((char*)new_c16, (char*)arg1, 16);
return (char16 *)(strncat((char*)new_c16, (char*)arg2, 16)); return (char16 *)(strncat((char*)new_c16, (char*)arg2, 16));
} }