sed errors when -e is given a 0-length argument
% echo "x" | /bin/sed -e ''
sed: asprintf: Error 0
case 'e': eflag = 1; if (asprintf(&temp_arg, "%s\n", optarg) <= 1) err(1, "asprintf"); add_compunit(CU_STRING, temp_arg); break;
This is wrong. It's entirely reasonable to end up passing a 0-length command to sed (I hit this during a build of gcc, which this bug causes to fail). sed should check the length and avoid calling add_compunit if it is 0 (probably even strlen(optarg), and skip the asprintf, too.).
Updated by Rich Lowe over 8 years ago
It would be easier to just change '<= 1' to '< 1'. (there should always be one character, the \n, if asprintf() really did not fail).
asprintf() also sets its first argument to NULL on failure, so the condition could be based on that, instead.
While asprintf is non-standard, it's too convenient to ignore out of hand for that reason, especially for systems software where we control the C library :)
Updated by Gary Mills over 8 years ago
I have a fix for this one that eliminates the problem
under OI 148b. I've decided to revert to the freebsd
code for two reasons. `asprintf' is only used in that
one place in the sed code, leaving no reason to retain
it. As well, there's no reason to alter the freebsd code
in this region. `sed' performs nicely without the change.
Look for a webrev soon.