bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PPP port: Code for setting gateway


From: Marcus Brinkmann
Subject: Re: PPP port: Code for setting gateway
Date: Sat, 25 Nov 2000 23:23:10 +0100
User-agent: Mutt/1.1.4i

On Sat, Nov 25, 2000 at 04:31:31PM -0500, Igor Khavkine wrote:
> >  
> >   sprintf(node_name, "%s/%d", _SERVERS_SOCKET, PF_INET);
> 
> Well, that's another segfault right there, you're trying to write
> to a wild pointer. Try:
> asprintf(&node_name, _SERVERS_SOCKET "%d", PF_INET);
> Actually you don't even have to use asprintf(), just allocate an array
> large enough to hold _SERVERS_SOCKET + largest integer. Too bad
> you can't embed a constant integer into a string at compile time.

Actually, you can at preprocessing time:

#define _GNU_SOURCE
#include <hurd/paths.h>
#include <sys/socket.h>

#define _SERVERS_SOCKET_SOME2(ARG) _SERVERS_SOCKET "/" #ARG
#define _SERVERS_SOCKET_SOME(ARG) _SERVERS_SOCKET_SOME2(ARG)
#define _SERVERS_SOCKET_PFINET _SERVERS_SOCKET_SOME(PF_INET)

main()
{
  printf(_SERVERS_SOCKET_PFINET);
}


(Or, more general, see libdiskfs/priv.h:

#define STRINGIFY(x) STRINGIFY_1(x)
#define STRINGIFY_1(x) #x

)

Thanks,
Marcus

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de



reply via email to

[Prev in Thread] Current Thread [Next in Thread]