Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Useless Assignment  at pvmd.c:4908

Categories: LANG.STRUCT.UA
Warning ID: 2659.2704
Procedure: mksocs
Trace: View
Modified: Wed Sep 2 12:42:40 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
LineSource
  /u1/paul/SATE/2010/c/pvm/pvm3/src/pvmd.c
  Enter mksocs
4834 mksocs() 
4835 {
4836         struct hostd *hp = hosts->ht_hosts[hosts->ht_local];   /* Buffer Overrun (ID: 2668.2713) */  /* Buffer Underrun (ID: 2667.2712) */
4837         struct hostd *hp0 = hosts->ht_hosts[0];
4838         struct sockaddr_in sin;
4839         char buf[128];
4840         char *sfn;
4841 #ifndef WIN32 
4842         int d;
4843 #else 
4844         HANDLE d;
4845         int e=0; 
4846 #endif 
4847 #ifndef NOSOCKOPT 
  ...
4865 #endif 
4866 #ifdef IMA_BEOLIN 
4867         struct hostent *hostaddr; 
4868 #endif 
4869         short tmpp;
4870  
4871         /*
4872         * make pvmd-pvmd socket 
4873         */ 
4874  
4875         if ((netsock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
4876                 pvmlogperror("mksocs() socket netsock");
4877                 return 1;
4878         }
4879  
4880         p = getenv("PVMNETSOCKPORT");
4881  
4882         tmpp = (p) ? atoi(p) : 0;
4883  
4884         hp->hd_sad.sin_port = htons(tmpp);
4885  
4886         do 
4887         {
4888                 oslen = sizeof(hp->hd_sad);
4889                 if ((cc=bind(netsock, (struct sockaddr*)&hp->hd_sad, oslen)) 
4890                                 == -1)
4891                 {
4892                         if (p) {
4893                                 tmpp++;
4894                                 hp->hd_sad.sin_port = htons(tmpp);
4895                         } else {
4896                                 pvmlogperror("mksocs() bind netsock");
4897                                 return 1;
4898                         }
4899                 }
4900         }
4901         while ( cc == -1 && p && hp->hd_sad.sin_port < 65535 );   /* Redundant Condition (ID: 2661.2706) */
4902  
4903         if ( cc == -1 ) {
4904                 pvmlogperror("mksocs() bind netsock");
4905                 return 1;
4906         }
4907  
4908         oslen = sizeof(hp->hd_sad);     /* Useless Assignment */
4909         if (getsockname(netsock, (struct sockaddr*)&hp->hd_sad, &oslen) == -1) {
4910                 pvmlogperror("mksocs() getsockname netsock");
4911                 return 1;
4912         }
4913  
4914         /*
4915         * make pvmd-pvmd' socket 
4916         */ 
4917  
4918         if ((ppnetsock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
4919                 pvmlogperror("mksocs() socket ppnetsock");
4920                 return 1;
4921         }
4922  
4923         hp0->hd_sad.sin_port = 0;
4924         oslen = sizeof(hp0->hd_sad);
4925         if (bind(ppnetsock, (struct sockaddr*)&hp0->hd_sad, oslen) == -1) {
4926                 pvmlogperror("mksocs() bind ppnetsock");
4927                 return 1;
4928         }
4929         oslen = sizeof(hp0->hd_sad);   /* Useless Assignment (ID: 2660.2705) */
4930         if (getsockname(ppnetsock, (struct sockaddr*)&hp0->hd_sad, &oslen) == -1) {
4931                 pvmlogperror("mksocs() getsockname ppnetsock");
4932                 return 1;
4933         }
4934  
4935         /*
4936         * make pvmd-local task socket 
4937         */ 
4938  
4939 #ifdef NOUNIXDOM 
4940         if ((loclsock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
4941                 pvmlogperror("mksocs() socket loclsock");
4942                 return 1;
  ...
5022         || setsockopt(ppnetsock, SOL_SOCKET, SO_RCVBUF,
5023                         (char*)&bsz, sizeof(bsz)) == -1) {
5024                 pvmlogperror("mksocs() setsockopt");
5025                 return 1;
5026         }
5027 #endif /*NOSOCKOPT*/ 
5028  
5029         p = inadport_hex(&sin); 
5030  
5031 #else /*NOUNIXDOM*/ 
5032         if ((loclsock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
5033                 pvmlogperror("mksocs() socket loclsock");
5034                 return 1;
5035         }
5036  
5037         BZERO((char*)&uns, sizeof(uns));
5038         uns.sun_family = AF_UNIX;
5039         spath[0] = 0;
5040         (void)PVMTMPNAMFUN(spath);
5041         strcpy(uns.sun_path, spath);
5042 /*
5043 XXX len?
5044 */ 
5045  
5046         oslen = sizeof(uns);
5047         if (bind(loclsock, (struct sockaddr*)&uns, oslen) == -1) {
5048                 pvmlogperror("mksocs() bind loclsock");
5049                 return 1;
5050         }
5051  
5052         if (listen(loclsock, SOMAXCONN) == -1) {
5053                 pvmlogperror("mksocs() listen loclsock");
5054                 return 1;
5055         }
5056  
5057         loclspath = STRALLOC(spath);   /* Null Pointer Dereference (ID: 2665.2710) */
5058         p = spath;
5059  
5060 #endif /*NOUNIXDOM*/ 
5061  
5062         /*
5063         * make pvmd-local task socket address file 
5064         */ 
5065  
5066         if (!(sfn = pvmdsockfile())) {
5067                 pvmlogerror("mksocs() pvmdsockfile() failed\n");
5068                 pvmbailout(0);
5069         }
5070  
5071 #ifndef WIN32 
5072         if ((d = open(sfn, O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0600)) == -1) {
5073                 if (errno == EEXIST) {
5074 #else 
5075         d = win32_create_file(sfn, CREATE_NEW);
5076         if ((int) d == -2){
5077                 /* this code is for WIN95 */ 
5078                 system_loser_win = TRUE;
5079                 e = _open(sfn,O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0600);
5080         }
5081         if (((int)d == -1) || (e ==-1)) {
5082                 if (1) {  /* errno == EEXIST */ 
5083 #endif 
5084 #ifndef OVERLOADHOST 
5085 #ifdef WIN32 
5086                         if (d == INVALID_HANDLE_VALUE) {
5087                                 (void) pvmlogprintf("mksocs() %s failed. You are required to run on NTFS\n", sfn);
5088                                 return 1; /* same as write address */ 
5089                         } else 
5090 #endif 
5091                         (void)pvmlogprintf( 
5092                                         "mksocs() %s exists.  pvmd already running?\n", sfn);
5093                         return 2;
5094 #endif 
5095  
5096                 } else {
5097                         pvmlogperror(sfn);
5098                         pvmlogerror("mksocs() can't write address file\n");
5099                         return 1;
5100                 }
5101         } else {
5102 #ifndef WIN32 
5103                 cc = write(d, p, strlen(p));
5104 #else 
5105                 CloseHandle(d);
5106                 if (!system_loser_win) {
5107                         if ((d = (HANDLE) win32_open_file(sfn)) == (HANDLE) -1) {
5108                                 pvmlogprintf("could not open file %s: %d \n",
5109                                                 sfn,GetLastError());
5110                         return 2;
5111                         }
5112                         cc = win32_write_file(d,p,strlen(p));
5113                 } else 
5114                         /* the win95 case */ 
5115                         cc = write(e,p,strlen(p)); 
5116 #endif 
5117                 if (cc != strlen(p)) {
5118                         if (cc == -1) {
5119                                 pvmlogperror(sfn);
5120                                 pvmlogerror("mksocs() can't write address file\n");
5121  
5122                         } else {
5123                                 (void)pvmlogprintf( 
5124                                                 "mksocs() aargh, short write on %s: %d\n",
5125                                                 sfn, cc);
5126                                 pvmlogerror("mksocs() is the partition full?\n");
5127                         }
5128 #ifndef WIN32 
5129                         (void)close(d);
5130 #else 
5131                         if (d)
5132                                 CloseHandle(d);
5133                         if (e)
5134                                 close(e); 
5135 #endif 
5136                         (void)unlink(sfn);
5137                         return 1;
5138                 }
5139                 loclsnam = STRALLOC(sfn);   /* Null Pointer Dereference (ID: 2664.2709) */
5140 #ifndef WIN32 
5141                 (void)close(d);
5142 #else 
5143                 if (d)
5144                         win32_close_file(d);
5145                 if (e)
5146                         close(e); 
5147 #endif 
5148         }
5149  
5150         /* set PVMSOCK envar */ 
5151  
5152         sprintf(buf, "PVMSOCK=%s", p);
5153         p = STRALLOC(buf);   /* Null Pointer Dereference (ID: 2663.2708) */  /* Leak (ID: 2662.2707) */
5154         pvmputenv(p);
5155  
5156         return 0;
5157 




Change Warning 2659.2704 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: