zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: trying dputs
Date: Thu, 20 Nov 2014 09:05:32 -0800	[thread overview]
Message-ID: <141120090532.ZM3683@torch.brasslantern.com> (raw)
In-Reply-To: <546D4854.1030604@eastlink.ca>

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.


  reply	other threads:[~2014-11-20 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20  1:48 Ray Andrews
2014-11-20 17:05 ` Bart Schaefer [this message]
2014-11-20 17:27   ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=141120090532.ZM3683@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).