mirror of
https://github.com/pengutronix/genimage.git
synced 2024-11-27 03:33:59 +08:00
util: introduce and use xrealloc
Just like xzalloc(). Abort when memory allocations fail. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
This commit is contained in:
parent
2672a5e604
commit
f69064ead3
@ -129,6 +129,7 @@ extern struct image_handler fit_handler;
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
void *xzalloc(size_t n);
|
||||
void *xrealloc(void *ptr, size_t size);
|
||||
unsigned long long strtoul_suffix(const char *str, char **endp,
|
||||
cfg_bool_t *percent);
|
||||
|
||||
|
14
util.c
14
util.c
@ -253,6 +253,18 @@ void *xzalloc(size_t n)
|
||||
return m;
|
||||
}
|
||||
|
||||
void *xrealloc(void *ptr, size_t size)
|
||||
{
|
||||
void *m = realloc(ptr, size);
|
||||
|
||||
if (!m) {
|
||||
error("out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like simple_strtoul() but handles an optional G, M, K or k
|
||||
* suffix for Gigabyte, Megabyte or Kilobyte
|
||||
@ -360,7 +372,7 @@ static int map_file_extents(struct image *image, const char *filename, int f,
|
||||
goto err_out;
|
||||
|
||||
/* Get extents */
|
||||
fiemap = realloc(fiemap, sizeof(struct fiemap) + fiemap->fm_mapped_extents * sizeof(struct fiemap_extent));
|
||||
fiemap = xrealloc(fiemap, sizeof(struct fiemap) + fiemap->fm_mapped_extents * sizeof(struct fiemap_extent));
|
||||
fiemap->fm_extent_count = fiemap->fm_mapped_extents;
|
||||
ret = ioctl(f, FS_IOC_FIEMAP, fiemap);
|
||||
if (ret == -1)
|
||||
|
Loading…
Reference in New Issue
Block a user