From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11838 invoked by alias); 3 Feb 2003 23:16:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 11816 invoked by uid 71); 3 Feb 2003 23:16:01 -0000 Resent-Date: 3 Feb 2003 23:16:01 -0000 Resent-Message-ID: <20030203231601.11815.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, jeronimo@mime.univ-paris8.fr Received: (qmail 8929 invoked by uid 48); 3 Feb 2003 23:06:08 -0000 Message-Id: <20030203230608.8928.qmail@sources.redhat.com> Date: Mon, 03 Feb 2003 23:16:00 -0000 From: jeronimo@mime.univ-paris8.fr Reply-To: jeronimo@mime.univ-paris8.fr To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/9557: gcc 2.95.3 20010315 (SuSE) problem with place of variable X-SW-Source: 2003-02/txt/msg00156.txt.bz2 List-Id: >Number: 9557 >Category: c >Synopsis: gcc 2.95.3 20010315 (SuSE) problem with place of variable >Confidential: no >Severity: non-critical >Priority: low >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Mon Feb 03 23:16:00 UTC 2003 >Closed-Date: >Last-Modified: >Originator: jerome Esteves >Release: unknown-1.0 >Organization: >Environment: Suse Linux 7.3 ("NO MODIFICATION") >Description: the problem is: when i put the variable port in his place i get a segmentation fault. if i move his place no error given. i give you the little code to reproduce the error, feel free to move the declaration of the variable port or make it int to avoid the problem. >How-To-Repeat: #include #include #include #include #include #include #define WARN(E) {perror(E); return NULL;} struct lien{ int sd; struct sockaddr_in adr4; }; /* the problem is with the variable port if i move its location after the variable ok i dont get an error */ struct lien * cree_socketTCP(char *n_host, char * n_service) { struct lien *con; short port; int ok=1; struct hostent *host; con=(struct lien *)malloc(sizeof(struct lien)); if(n_host!=NULL) if((host = gethostbyname(n_host)) == NULL) WARN("gethostbyname:"); if(con ==NULL) WARN("Malloc:"); if((con->sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0 ) WARN("socket:"); memset(&con->adr4, 0, sizeof(struct sockaddr_in)); con->adr4.sin_family = AF_INET; setsockopt(con->sd, SOL_SOCKET, SO_REUSEADDR, &ok, sizeof(int)); if( n_service!=NULL) { if((sscanf(n_service, "%d", &port))==1) con->adr4.sin_port =htons(port); else WARN("bad port"); } if(n_host != NULL) con->adr4.sin_addr.s_addr=((struct in_addr *)(host->h_addr))->s_addr; if(bind(con->sd, (struct sockaddr *)&con->adr4, sizeof(struct sockaddr_in))<0){ close(con->sd); perror("bind:"); return NULL; } return con; } int main() { cree_socketTCP("0.0.0.0", "1235"); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: