From: Tony Cook Date: Fri, 27 Jan 2006 03:09:59 +0000 (+0000) Subject: - handle the possibility of strerror() returning NULL. X-Git-Tag: Imager-0.48^2~31 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/40d75d5ad738fdfcfb81652f1f3634440348a9f3 - handle the possibility of strerror() returning NULL. --- diff --git a/Changes b/Changes index 7a6d86ce..8d27eb37 100644 --- a/Changes +++ b/Changes @@ -1314,6 +1314,7 @@ Revision history for Perl extension Imager. - added typemap type names to types in Imager::API. - make skip when Inline::C not available less verbose - convert t/t07iolayer.t to Test::More +- handle the possibility of strerror() returning NULL. ================================================================= diff --git a/iolayer.c b/iolayer.c index a425bff8..b98494bc 100644 --- a/iolayer.c +++ b/iolayer.c @@ -64,6 +64,7 @@ static ssize_t fd_write(io_glue *ig, const void *buf, size_t count); static off_t fd_seek(io_glue *ig, off_t offset, int whence); static void fd_close(io_glue *ig); static ssize_t fd_size(io_glue *ig); +static const char *my_strerror(int err); /* * Callbacks for sources that cannot seek @@ -1073,7 +1074,7 @@ static ssize_t fd_read(io_glue *ig, void *buf, size_t count) { /* 0 is valid - means EOF */ if (result < 0) { - i_push_errorf(0, "read() failure: %s (%d)", strerror(errno), errno); + i_push_errorf(0, "read() failure: %s (%d)", my_strerror(errno), errno); } return result; @@ -1088,7 +1089,7 @@ static ssize_t fd_write(io_glue *ig, const void *buf, size_t count) { #endif if (result <= 0) { - i_push_errorf(errno, "write() failure: %s (%d)", strerror(errno), errno); + i_push_errorf(errno, "write() failure: %s (%d)", my_strerror(errno), errno); } return result; @@ -1103,7 +1104,7 @@ static off_t fd_seek(io_glue *ig, off_t offset, int whence) { #endif if (result == (off_t)-1) { - i_push_errorf(errno, "lseek() failure: %s (%d)", strerror(errno), errno); + i_push_errorf(errno, "lseek() failure: %s (%d)", my_strerror(errno), errno); } return result; @@ -1167,6 +1168,32 @@ io_glue_DESTROY(io_glue *ig) { myfree(ig); } +/* +=back + +=head1 INTERNAL FUNCTIONS + +=over + +=item my_strerror + +Calls strerror() and ensures we don't return NULL. + +On some platforms it's possible for strerror() to return NULL, this +wrapper ensures we only get non-NULL values. + +=cut +*/ + +static +const char *my_strerror(int err) { + const char *result = strerror(err); + + if (!result) + result = "Unknown error"; + + return result; +} /* =back