From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 21 11:59:31 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 754C937B401 for ; Mon, 21 Jul 2003 11:59:31 -0700 (PDT) Received: from ussenterprise.ufp.org (ussenterprise.ufp.org [208.185.30.210]) by mx1.FreeBSD.org (Postfix) with ESMTP id 09BC343FAF for ; Mon, 21 Jul 2003 11:59:30 -0700 (PDT) (envelope-from bicknell@ussenterprise.ufp.org) Received: from ussenterprise.ufp.org (bicknell@localhost [127.0.0.1]) by ussenterprise.ufp.org (8.12.9/8.12.9) with ESMTP id h6LIxS8i061823 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 21 Jul 2003 14:59:28 -0400 (EDT) Received: (from bicknell@localhost) by ussenterprise.ufp.org (8.12.9/8.12.9/Submit) id h6LIxSUM061822; Mon, 21 Jul 2003 14:59:28 -0400 (EDT) Date: Mon, 21 Jul 2003 14:59:28 -0400 From: Leo Bicknell To: Tim Kientzle , Chad David , hackers@freebsd.org Message-ID: <20030721185928.GA61664@ussenterprise.ufp.org> Mail-Followup-To: Tim Kientzle , Chad David , hackers@freebsd.org References: <3F1B0610.90803@acm.org> <20030720225041.GA26277@ussenterprise.ufp.org> <3F1C0C91.6050203@acm.org> <20030721165735.GA56766@ussenterprise.ufp.org> <20030721171538.GA21656@colnta.acns.ab.ca> <20030721172321.GA57666@ussenterprise.ufp.org> <20030721174206.GA21892@colnta.acns.ab.ca> <3F1C2FEB.4070801@acm.org> <20030721185217.GA60600@ussenterprise.ufp.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="fdj2RfSjLxBAspz7" Content-Disposition: inline In-Reply-To: <20030721185217.GA60600@ussenterprise.ufp.org> Organization: United Federation of Planets X-PGP-Key: http://www.ufp.org/~bicknell/ Subject: Re: Correct way to call execve? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2003 18:59:31 -0000 --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable You know, my own thinking made me figure this one out: % cat exec.c #include #include #include int main(int argc, char *const argv[], char *const envp[]) { char *const execargv[] =3D { _PATH_BSHELL, NULL }; execve(_PATH_BSHELL,execargv,NULL); return 0; } % cc -fwritable-strings -Wcast-qual -Wwrite-strings exec.c % There you go. By default strings are read-only, and indeed smart compilers use that to compress them and do other nifty tricks. However, in this case you really want a string to be "char *", eg writable. So, tell the compiler to do that with "-fwritable-strings", poof, strings are now "char *", the cast away the cost problem goes away, "-Wcast-qual" works fine. It always seemed to me a lot of things included -fwritable-strings for no good reason, maybe this is part of the reason. :) --=20 Leo Bicknell - bicknell@ufp.org - CCIE 3440 PGP keys at http://www.ufp.org/~bicknell/ Read TMBG List - tmbg-list-request@tmbg.org, www.tmbg.org --fdj2RfSjLxBAspz7 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE/HDgQNh6mMG5yMTYRAss6AJ9B2Gsn12fNl7q1vbgFdZVVIfde4wCfXPt3 358e2u8S2Z0Tb0wYk6V/mvI= =ThYH -----END PGP SIGNATURE----- --fdj2RfSjLxBAspz7--