public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: jeronimo@mime.univ-paris8.fr
To: gcc-gnats@gcc.gnu.org
Subject: c/9557: gcc  2.95.3 20010315 (SuSE) problem with place of variable
Date: Mon, 03 Feb 2003 23:16:00 -0000	[thread overview]
Message-ID: <20030203230608.8928.qmail@sources.redhat.com> (raw)


>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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>


#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#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:


             reply	other threads:[~2003-02-03 23:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-03 23:16 jeronimo [this message]
2003-02-03 23:42 bangerth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030203230608.8928.qmail@sources.redhat.com \
    --to=jeronimo@mime.univ-paris8.fr \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).