From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22146 invoked by alias); 20 Nov 2014 17:27:37 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33726 Received: (qmail 3191 invoked from network); 20 Nov 2014 17:27:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Authority-Analysis: v=2.1 cv=HYUtEE08 c=1 sm=1 tr=0 a=3lbMEJa4VuzO22difQnlXw==:117 a=3lbMEJa4VuzO22difQnlXw==:17 a=G8GL833Es-AA:10 a=N659UExz7-8A:10 a=NpQEqAgp733kCeygEUAA:9 a=pILNOxqGKmIA:10 Message-id: <546E247B.9000704@eastlink.ca> Date: Thu, 20 Nov 2014 09:27:23 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.2.0 MIME-version: 1.0 To: zsh-workers@zsh.org Subject: Re: trying dputs References: <546D4854.1030604@eastlink.ca> <141120090532.ZM3683@torch.brasslantern.com> In-reply-to: <141120090532.ZM3683@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 11/20/2014 09:05 AM, Bart Schaefer wrote: > On Nov 19, 5:48pm, Ray Andrews wrote: > } > } If I steal 'opts->args' with a test string like this: > } > } //char *garbage = "utter garbage"; > } //ops->args = &garbage; > } > } ... I get what I expect from this: > } > } dputs("\nargs: %s", *(ops->args)); > } > } ... but if I leave the pointer unmolested, I get a zsh > } segmentation fault. Why is that? > > Because ops->args is a NULL pointer (not a pointer to an empty string) > when there are no arguments to the option. Dereferencing a NULL pointer > is a segmentation fault in most cases; if you are used to getting "NULL" > as output from printf("%s\n", (char *)0), then you've been damaged by an > overly generous compiler or an overly protective OS. If it's supposta be NULL when not in use, then I got what I should get, quite right. I just thought it might more safely point to a NULL string, but if that's not how it's done, then it's probably for a good reason. I can't say otherwise. > > Look at the definitions of OPT_ARG and OPT_ARG_SAFE in zsh.h. You should > not be dereferencing ops->args directly, even in a debugging statement. Ok. Easy enough to test for a NULL pointer in any case.