Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: trying dputs



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.



Messages sorted by: Reverse Date, Date, Thread, Author