[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/6] ios: Check ios->handler_normalize for memory allocation
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH 3/6] ios: Check ios->handler_normalize for memory allocation error. |
Date: |
Thu, 07 May 2020 18:42:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
# gnulib modules used in libpoke/.
libpoke_modules="
+ errno
fstat
gcd
gettext-h
Should we be using the global `errno' at all in a library?
diff --git a/libpoke/ios.c b/libpoke/ios.c
index ebf5f5bc..74fd3719 100644
--- a/libpoke/ios.c
+++ b/libpoke/ios.c
@@ -26,6 +26,7 @@
#include <limits.h>
#define _(str) gettext (str)
#include <streq.h>
+#include <errno.h>
#include "pk-utils.h"
#include "ios.h"
@@ -120,7 +121,7 @@ ios_open (const char *handler, uint64_t flags, int
set_cur)
{
struct ios *io = NULL;
struct ios_dev_if **dev_if = NULL;
- int error, ret;
+ int error = IOD_ERROR, ret;
/* Allocate and initialize the new IO space. */
io = xmalloc (sizeof (struct ios));
@@ -130,11 +131,14 @@ ios_open (const char *handler, uint64_t flags, int
set_cur)
/* Look for a device interface suitable to operate on the given
handler. */
+ errno = 0;
for (dev_if = ios_dev_ifs; *dev_if; ++dev_if)
{
io->handler = (*dev_if)->handler_normalize (handler);
if (io->handler)
break;
+ if (errno == ENOMEM)
+ goto error;
}
if (*dev_if == NULL)
Why would be want to check for `errno' after calling handler_normalize?
The function does not return any error code.
[PATCH 4/6] poke: Add new function pk_assert_alloc, Tim Rühsen, 2020/05/07
[PATCH 5/6] poke: Remove unneeded header includes., Tim Rühsen, 2020/05/07