From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11174 invoked by alias); 20 Nov 2014 17:05:15 -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: 33724 Received: (qmail 25128 invoked from network); 20 Nov 2014 17:05:04 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=GfugRrTO c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=5y4faFyK3SkA:10 a=42hV-Oi6obCJ8Y5IzagA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <141120090532.ZM3683@torch.brasslantern.com> Date: Thu, 20 Nov 2014 09:05:32 -0800 In-reply-to: <546D4854.1030604@eastlink.ca> Comments: In reply to Ray Andrews "trying dputs" (Nov 19, 5:48pm) References: <546D4854.1030604@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: trying dputs MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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. 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.