Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jul 2003 14:59:28 -0400
From:      Leo Bicknell <bicknell@ufp.org>
To:        Tim Kientzle <kientzle@acm.org>, Chad David <davidc@issci.ca>, hackers@freebsd.org
Subject:   Re: Correct way to call execve?
Message-ID:  <20030721185928.GA61664@ussenterprise.ufp.org>
In-Reply-To: <20030721185217.GA60600@ussenterprise.ufp.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>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <unistd.h>
#include <paths.h>
#include <string.h>

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030721185928.GA61664>