Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80c1e82

Browse files
author
Thomas G. Lockhart
committed
Unscramble port selection logic to avoid compiler complaints about
uninitialized variables. I _think_ the logic is preserved...
1 parentc2f4779 commit80c1e82

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.46 1997/11/14 15:38:31 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.47 1997/11/17 16:42:39 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -350,49 +350,43 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
350350
conn->port=NULL;
351351
conn->notifyList=DLNewList();
352352

353-
if (!pghost||pghost[0]=='\0')
353+
if ((pghost==NULL)||pghost[0]=='\0')
354354
{
355355
conn->pghost=NULL;
356-
if (tmp=getenv("PGHOST"))
356+
if ((tmp=getenv("PGHOST"))!=NULL)
357357
conn->pghost=strdup(tmp);
358358
}
359359
else
360360
conn->pghost=strdup(pghost);
361361

362-
if (!pgport||pgport[0]=='\0')
362+
if ((pgport==NULL)||pgport[0]=='\0')
363363
{
364-
if (!(tmp=getenv("PGPORT")))
365-
{
364+
if ((tmp=getenv("PGPORT"))==NULL)
366365
tmp=DEF_PGPORT;
367-
}
368366
conn->pgport=strdup(tmp);
369367
}
370368
else
371369
conn->pgport=strdup(pgport);
372370

373-
if (!pgtty||pgtty[0]=='\0')
371+
if ((pgtty==NULL)||pgtty[0]=='\0')
374372
{
375-
if (!(tmp=getenv("PGTTY")))
376-
{
373+
if ((tmp=getenv("PGTTY"))==NULL)
377374
tmp=DefaultTty;
378-
}
379375
conn->pgtty=strdup(tmp);
380376
}
381377
else
382378
conn->pgtty=strdup(pgtty);
383379

384-
if (!pgoptions||pgoptions[0]=='\0')
380+
if ((pgoptions==NULL)||pgoptions[0]=='\0')
385381
{
386-
if (!(tmp=getenv("PGOPTIONS")))
387-
{
382+
if ((tmp=getenv("PGOPTIONS"))==NULL)
388383
tmp=DefaultOption;
389-
}
390384
conn->pgoptions=strdup(tmp);
391385
}
392386
else
393387
conn->pgoptions=strdup(pgoptions);
394388

395-
if ((tmp=getenv("PGUSER")))
389+
if ((tmp=getenv("PGUSER"))!=NULL)
396390
{
397391
error= FALSE;
398392
conn->pguser=strdup(tmp);
@@ -413,19 +407,15 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
413407
}
414408
}
415409

416-
if ((tmp=getenv("PGPASSWORD")))
417-
{
410+
if ((tmp=getenv("PGPASSWORD"))!=NULL)
418411
conn->pgpass=strdup(tmp);
419-
}
420412
else
421-
{
422413
conn->pgpass=0;
423-
}
424414

425415
if (!error)
426416
{
427-
if (((tmp= (char*)dbName)&& (dbName[0]!='\0'))||
428-
((tmp=getenv("PGDATABASE"))))
417+
if ((((tmp= (char*)dbName)!=NULL)&& (dbName[0]!='\0'))
418+
||((tmp=getenv("PGDATABASE"))))
429419
conn->dbName=strdup(tmp);
430420
else
431421
conn->dbName=strdup(conn->pguser);
@@ -523,17 +513,25 @@ connectDB(PGconn *conn)
523513
port= (Port*)malloc(sizeof(Port));
524514
MemSet((char*)port,0,sizeof(Port));
525515

526-
if (conn->pghost&&
527-
(!(hp=gethostbyname(conn->pghost))||hp->h_addrtype!=AF_INET))
516+
if (conn->pghost!=NULL)
528517
{
529-
(void)sprintf(conn->errorMessage,
530-
"connectDB() -- unknown hostname: %s\n",
531-
conn->pghost);
532-
gotoconnect_errReturn;
533-
}
518+
hp=gethostbyname(conn->pghost);
519+
if ((hp==NULL)|| (hp->h_addrtype!=AF_INET))
520+
{
521+
(void)sprintf(conn->errorMessage,
522+
"connectDB() -- unknown hostname: %s\n",
523+
conn->pghost);
524+
gotoconnect_errReturn;
525+
}
526+
}else
527+
hp=NULL;
528+
529+
#ifFALSE
534530
MemSet((char*)&port->raddr,0,sizeof(port->raddr));
531+
#endif
535532
portno=atoi(conn->pgport);
536-
port->raddr.in.sin_family=family=conn->pghost ?AF_INET :AF_UNIX;
533+
family= (conn->pghost!=NULL) ?AF_INET :AF_UNIX;
534+
port->raddr.in.sin_family=family;
537535
if (family==AF_INET)
538536
{
539537
memmove((char*)&(port->raddr.in.sin_addr),
@@ -620,15 +618,15 @@ connectDB(PGconn *conn)
620618
}
621619

622620
/* free the password so it's not hanging out in memory forever */
623-
if (conn->pgpass)
621+
if (conn->pgpass!=NULL)
624622
{
625623
free(conn->pgpass);
626624
}
627625

628626
/* set up the socket file descriptors */
629627
conn->Pfout=fdopen(port->sock,"w");
630628
conn->Pfin=fdopen(dup(port->sock),"r");
631-
if (!conn->Pfout||!conn->Pfin)
629+
if ((conn->Pfout==NULL)||(conn->Pfin==NULL))
632630
{
633631
(void)sprintf(conn->errorMessage,
634632
"connectDB() -- fdopen() failed: errno=%d\n%s\n",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp