]> Trent Huber's Code - xpmview.git/commitdiff
Remove allocate(), update cbs and raylib
authorTrent Huber <trentmhuber@gmail.com>
Fri, 19 Dec 2025 06:45:14 +0000 (01:45 -0500)
committerTrent Huber <trentmhuber@gmail.com>
Fri, 19 Dec 2025 06:45:14 +0000 (01:45 -0500)
external/cbs
external/cbsfile.c
external/raylib
src/cbs.h
src/main.c
src/options.c
src/xpm.c

index fd0804d9e6ab56e82c739af0ad8789f121c0288e..3d6f93f0f85b9404750dc0a50589abc175b185f6 160000 (submodule)
@@ -1 +1 @@
-Subproject commit fd0804d9e6ab56e82c739af0ad8789f121c0288e
+Subproject commit 3d6f93f0f85b9404750dc0a50589abc175b185f6
index 4e9453fd51fbc64e4d8214559d1ca36d102b6e43..bceeba7bb68036a3d049f0e3c91a428b11645dfe 100644 (file)
@@ -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;
index 4b760091da1da052a23f180a7e01c5d763d2875f..13f9112d8c069ed333acf72c2c1b94a0533c6dc1 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4b760091da1da052a23f180a7e01c5d763d2875f
+Subproject commit 13f9112d8c069ed333acf72c2c1b94a0533c6dc1
index d77f220a57e70233ccd60c84ea56c90efaba12bb..076fca5de9e7892905d2474c4de408d9018577e9 100644 (file)
--- 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);
index af675e2f5811ede7e17cb2120901919ae9ca3fc8..b24259f46a6751dbdc51116705f2acdd2a9d980f 100644 (file)
@@ -1,3 +1,4 @@
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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);
index 63f9bba8250305e8ef9fd2cd2206e545291417c0..d21db18bfea5023226e2dc35110c99748f08b67c 100644 (file)
@@ -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':
index 3a001006561dbcc175ca0878add9bbc040b346c1..98a6d1a7fe6243da091893de64a3ea36c0e797c1 100644 (file)
--- 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];