From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 21 08:50:47 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 9C9A337B401 for ; Mon, 21 Jul 2003 08:50:47 -0700 (PDT) Received: from kientzle.com (h-66-166-149-50.SNVACAID.covad.net [66.166.149.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 11D1C43F3F for ; Mon, 21 Jul 2003 08:50:47 -0700 (PDT) (envelope-from kientzle@acm.org) Received: from acm.org ([66.166.149.53]) by kientzle.com (8.12.9/8.12.9) with ESMTP id h6LFoksE020054; Mon, 21 Jul 2003 08:50:46 -0700 (PDT) (envelope-from kientzle@acm.org) Message-ID: <3F1C0C91.6050203@acm.org> Date: Mon, 21 Jul 2003 08:53:53 -0700 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.0.1) Gecko/20021005 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Leo Bicknell References: <3F1B0610.90803@acm.org> <20030720225041.GA26277@ussenterprise.ufp.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: hackers@freebsd.org Subject: Re: Correct way to call execve? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: kientzle@acm.org 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 15:50:47 -0000 Leo Bicknell wrote: > In a message written on Sun, Jul 20, 2003 at 02:13:52PM -0700, Tim Kientzle wrote: >>If I declare argv as "const char *", >>then the call to execve() warns about >>"incompatible pointer type" for the >>second argument. > > Almost, but the other order is important here, this passes gcc -Wall: > > #include > #include > > int main(int argc, char *const argv[], char *const envp[]) { > char *const execargv[] = { _PATH_BSHELL, NULL }; > > execve(_PATH_BSHELL,execargv,envp); > > return 0; > } Actually, this example passes -Wall if you declare "execargv" as simply "char *[]". However, I'm looking for something that passes gcc -Wwrite-strings, which this example does not. I honestly don't believe it is possible to call execve() in a const-correct fashion with -Wwrite-strings unless you copy over all of the arguments into non-const storage. I'd love to be proven wrong, though. Tim Kientzle