On Wed, 26 Jul 2017 12:10:53 +0200, Ingo Schwarze wrote: > As related data points, for EOVERFLOW, we do always return -1, > and for EILSEQ, we changed the code some time ago to return -1 - > even though in both of these cases, it is not completely obvious > whether those should be considered "output errors" in the POSIX > sense. > > For ENOMEM, both glibc and Solaris 11 return -1 according to my > testing, and NetBSD does the same according to code inspection. In > FreeBSD, my impression is that dtoa() uses malloc(3), too, but i > failed to find any error handling code, so i guess they chose to > simply segfault - not sure, though. > > > In summary, i think we ought to return -1. > > It's the only option that allows a sane usage pattern (and in > particular the one that people *are* actually using, if they check > for errors at all), POSIX at least doesn't forbid it, and most > others seem to do it, too.
I agree. People assume that asprintf() will return -1 on malloc failure. Doing anything else is going to create subtle bugs. - todd