diff options
author | Zack Weinberg <zackw@panix.com> | 2017-04-01 17:13:45 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-04-07 07:51:52 -0400 |
commit | aeacb9f9127cff0ed099026156ca35c025f343b7 (patch) | |
tree | bfb225c266f739bae9a3c96f9313801e305b98f5 /ChangeLog | |
parent | dfbea09f96ce9e7a56f88c47d1593f07dc55c53c (diff) | |
download | glibc-aeacb9f9127cff0ed099026156ca35c025f343b7.tar.gz glibc-aeacb9f9127cff0ed099026156ca35c025f343b7.tar.xz glibc-aeacb9f9127cff0ed099026156ca35c025f343b7.zip |
getopt: merge from gnulib: alloca avoidance
In one place, glibc's getopt uses alloca to construct a linked list of possibilities for an "ambiguous" long option. In gnulib, malloc should be used instead. Providing for both cases complicates things a fair bit. Instead of merging straight across, therefore, I have chosen to rewrite it using a boolean vector instead of a linked list. There is then only one allocation that might need freeing; in glibc it can honor __libc_use_alloca as usual, and in gnulib we define __libc_use_alloca to always be false, so we don't need ifdefs in the middle of the function. This should also be slightly more efficient in the normal case of long options being fully spelled out -- I think most people aren't even aware they _can_ sometimes abbreviate long options. One interesting consequence is that the list of possibilities is now printed in exactly the order they appear in the list of long options, instead of the first possibility being shuffled to the end. This shouldn't be a big deal but it did break one test that relied on the exact text of this error message. (The reason the previous patch was "in aid of" merging from gnulib is I didn't want to have to make this change in two places.) (The patch looks bigger than it really is because there's a fair bit of reindentation and code rearrangement.) * posix/getopt.c: When used standalone, define __libc_use_alloca as always false and alloca to abort if called. (process_long_option): Rewrite handling of ambiguous long options to use a single boolean vector, not a linked list; use __libc_use_alloca to decide whether to allocate this using alloca. * posix/tst-getopt_long1.c: Adjust text of expected error message.
Diffstat (limited to 'ChangeLog')
-rw-r--r-- | ChangeLog | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog index cf663d1b5f..4b8371a148 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2017-04-07 Zack Weinberg <zackw@panix.com> + * posix/getopt.c: When used standalone, define __libc_use_alloca + as always false and alloca to abort if called. + (process_long_option): Rewrite handling of ambiguous long options + to use a single boolean vector, not a linked list; use + __libc_use_alloca to decide whether to allocate this using alloca. + * posix/tst-getopt_long1.c: Adjust text of expected error message. + * posix/getopt.c (process_long_option): New function split out from _getopt_internal_r. (_getopt_internal_r): Replace both copies of the long-option |