[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/4] ios: Remove usage of xalloc from ios-dev-mem.c
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH 3/4] ios: Remove usage of xalloc from ios-dev-mem.c |
Date: |
Thu, 14 May 2020 21:19:11 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Tim.
This looks OK.
Thanks!
2020-05-07 Tim Rühsen <address@hidden>
* libpoke/ios-dev-mem.c (ios_dev_mem_open): Replace
xzalloc by calloc.
(ios_dev_mem_pwrite): Replace xrealloc with realloc.
Remove include xalloc.h.
---
ChangeLog | 7 +++++++
libpoke/ios-dev-mem.c | 29 +++++++++++++++++++++++------
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/libpoke/ios-dev-mem.c b/libpoke/ios-dev-mem.c
index 88b370ad..fba99d41 100644
--- a/libpoke/ios-dev-mem.c
+++ b/libpoke/ios-dev-mem.c
@@ -20,7 +20,6 @@
#include <string.h>
#include <stdlib.h>
-#include <xalloc.h>
#include "ios.h"
#include "ios-dev.h"
@@ -47,10 +46,18 @@ ios_dev_mem_handler_normalize (const char *handler)
static void *
ios_dev_mem_open (const char *handler, uint64_t flags, int *error)
{
- struct ios_dev_mem *mio;
+ struct ios_dev_mem *mio = malloc (sizeof (struct ios_dev_mem));
+
+ if (!mio)
+ return NULL;
+
+ mio->pointer = calloc (MEM_STEP, 1);
+ if (!mio->pointer)
+ {
+ free (mio);
+ return NULL;
+ }
- mio = xmalloc (sizeof (struct ios_dev_mem));
- mio->pointer = xzalloc (MEM_STEP);
mio->size = MEM_STEP;
mio->flags = flags;
@@ -97,12 +104,22 @@ ios_dev_mem_pwrite (void *iod, const void *buf, size_t
count,
if (offset + count > mio->size + MEM_STEP)
return IOD_EOF;
+
if (offset + count > mio->size) {
- mio->pointer = xrealloc (mio->pointer,
- mio->size + MEM_STEP);
+ void *pointer_bak = mio->pointer;
+
+ mio->pointer = realloc (mio->pointer, mio->size + MEM_STEP);
+ if (!mio->pointer)
+ {
+ /* Restore pointer after failed realloc and return error. */
+ mio->pointer = pointer_bak;
+ return IOD_ERROR;
+ }
+
memset (&mio->pointer[mio->size], 0, MEM_STEP);
mio->size += MEM_STEP;
}
+
memcpy (&mio->pointer[offset], buf, count);
return 0;
}
--
2.26.2
- [PATCH 1/4] ios: Remove usage of xalloc from ios-dev-file.c, Tim Rühsen, 2020/05/14
- [PATCH 4/4] ios: Remove usage of xalloc from ios.c, Tim Rühsen, 2020/05/14
- [PATCH 3/4] ios: Remove usage of xalloc from ios-dev-mem.c, Tim Rühsen, 2020/05/14
- Re: [PATCH 3/4] ios: Remove usage of xalloc from ios-dev-mem.c,
Jose E. Marchesi <=
- [PATCH 2/4] ios: Remove usage of xalloc from ios-dev-nbd.c, Tim Rühsen, 2020/05/14
- Re: [PATCH 1/4] ios: Remove usage of xalloc from ios-dev-file.c, Jose E. Marchesi, 2020/05/14
- Re: [PATCH 1/4] ios: Remove usage of xalloc from ios-dev-file.c, Tim Rühsen, 2020/05/15