From: Trent Huber Date: Fri, 19 Dec 2025 06:45:14 +0000 (-0500) Subject: Remove allocate(), update cbs and raylib X-Git-Url: https://trenthuber.com/code?a=commitdiff_plain;h=7c3e987f3e609375969882c8b8c444ed5019ba35;p=xpmview.git Remove allocate(), update cbs and raylib --- diff --git a/external/cbs b/external/cbs index fd0804d..3d6f93f 160000 --- a/external/cbs +++ b/external/cbs @@ -1 +1 @@ -Subproject commit fd0804d9e6ab56e82c739af0ad8789f121c0288e +Subproject commit 3d6f93f0f85b9404750dc0a50589abc175b185f6 diff --git a/external/cbsfile.c b/external/cbsfile.c index 4e9453f..bceeba7 100644 --- a/external/cbsfile.c +++ b/external/cbsfile.c @@ -17,7 +17,8 @@ void buildfiles(struct cbsfile *files) { compile(files[i].name); } - names = allocate(i + 1, sizeof*names); + if (!(names = calloc(i + 1, sizeof*names))) + err(EXIT_FAILURE, "Memory allocation"); for (i = 0; files[i].name; ++i) names[i] = files[i].name; lflags = target->flags; diff --git a/external/raylib b/external/raylib index 4b76009..13f9112 160000 --- a/external/raylib +++ b/external/raylib @@ -1 +1 @@ -Subproject commit 4b760091da1da052a23f180a7e01c5d763d2875f +Subproject commit 13f9112d8c069ed333acf72c2c1b94a0533c6dc1 diff --git a/src/cbs.h b/src/cbs.h index d77f220..076fca5 100644 --- a/src/cbs.h +++ b/src/cbs.h @@ -9,6 +9,5 @@ extern char **cflags, **lflags; -void *allocate(size_t num, size_t size); void compile(char *src); void load(char type, char *target, char **objs); diff --git a/src/main.c b/src/main.c index af675e2..b24259f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -21,7 +22,8 @@ static void handleinput(void) { if (IsFileDropped()) { files = LoadDroppedFiles(); if (xpm) free(xpm); - xpm = allocate(FILENAME_MAX, sizeof*xpm); + if (!(xpm = calloc(FILENAME_MAX, sizeof*xpm))) + err(EXIT_FAILURE, "Memory allocation"); strcpy(xpm, files.paths[0]); UnloadDroppedFiles(files); texture = reloadtexture(xpm, mode); diff --git a/src/options.c b/src/options.c index 63f9bba..d21db18 100644 --- a/src/options.c +++ b/src/options.c @@ -33,7 +33,8 @@ int options(int argc, char **argv) { debug = 1; break; case 'f': - xpm = allocate(FILENAME_MAX, sizeof*xpm); + if (!(xpm = calloc(FILENAME_MAX, sizeof*xpm))) + err(EXIT_FAILURE, "Memory allocation"); strcpy(xpm, optarg); break; case 'h': diff --git a/src/xpm.c b/src/xpm.c index 3a00100..98a6d1a 100644 --- a/src/xpm.c +++ b/src/xpm.c @@ -45,7 +45,8 @@ static char *getname(char *p, size_t l) { } for (start = p; !space(*p) && *p != '['; ++p, --l) if (l == 0) return NULL; - r = allocate((l = p - start) + 1, sizeof*r); + if (!(r = calloc((l = p - start) + 1, sizeof*r))) + err(EXIT_FAILURE, "Memory allocation"); strncpy(r, start, l); return r; @@ -155,8 +156,9 @@ static void parse(char **data, long *sizep) { } /* Colors */ - chars = allocate(ncolors * cpp, sizeof*chars); - colors = allocate(NUMMODES * ncolors, sizeof*colors); + if (!(chars = calloc(ncolors * cpp, sizeof*chars)) + || !(colors = calloc(NUMMODES * ncolors, sizeof*colors))) + err(EXIT_FAILURE, "Memory allocation"); for (i = 0; i < ncolors; ++i) { strncpy(chars + i * cpp, p = data[1 + i], cpp); p += cpp; @@ -175,7 +177,8 @@ static void parse(char **data, long *sizep) { } /* Pixels */ - pixels = allocate(NUMMODES * height * width, sizeof*pixels); + if (!(pixels = calloc(NUMMODES * height * width, sizeof*pixels))) + err(EXIT_FAILURE, "Memory allocation"); j = width; l = 0; for (i = 0, pp = &data[1 + ncolors];