On 16/02/15 20:06, Tobias Stoeckmann wrote: > In contrast to glibc's getopt implementation, this one uses malloc instead > of alloca. While in general this is a good idea, malloc returns NULL in > case of error, therefore the return value should be checked. > > The fprintf statements are copied from the same source file; I am rather > indifferent about the error message. > > Using coreutils' ls (I verified that gnulib's getopt is used on my system): > > tobias:~/git/coreutils$ ulimit -Sv 4226 > tobias:~/git/coreutils$ ./src/ls --t > Segmentation fault
Yes we shouldn't segfault. That change came with http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=70aa91cc > With this patch: > > tobias:~/git/coreutils$ ./src/ls --t > ./src/ls: out of memory, dropping option 'time' while resolving ambiguity > ./src/ls: out of memory, dropping option 'time-style' while resolving > ambiguity > ./src/ls: option '--tabsize' requires an argument > Try './src/ls --help' for more information. I'm not sure it's generally worth proceeding in OOM conditions unless there are clear fall backs. It would be nice to depend on xalloc and just call xmalloc(). Could this suffice? #ifdef _LIBC struct option_list *newp = alloca (sizeof (*newp)); #else struct option_list *newp = xmalloc (sizeof (*newp)); #endif thanks! Pádraig.