]> Trent Huber's Code - xpmview.git/commitdiff
New allocate() signature from cbs
authorTrent Huber <trentmhuber@gmail.com>
Sun, 16 Nov 2025 10:03:24 +0000 (05:03 -0500)
committerTrent Huber <trentmhuber@gmail.com>
Sun, 16 Nov 2025 10:03:24 +0000 (05:03 -0500)
build.h
external/cbs
external/cbsfile.c
src/cbs.h
src/main.c
src/options.c
src/xpm.c

diff --git a/build.h b/build.h
index e87a95d9f92cc9d7b9e1a600691d5a6f202cb760..acdf8ebaa9f6dc053828b5d46b5317169f709a9c 100644 (file)
--- a/build.h
+++ b/build.h
@@ -1,5 +1,5 @@
 // Rebuild with the following #define to use Raylib as a dynamic library
-// #define DYNAMICLIBS
+#define DYNAMICLIBS
 
 #ifdef __APPLE__
 #define LFRAYLIB \
index 011c66e9c2332506752b701fdfa37739dde67f6a..d6f96a0fa0b51e77492eee931de23021f69326a1 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 011c66e9c2332506752b701fdfa37739dde67f6a
+Subproject commit d6f96a0fa0b51e77492eee931de23021f69326a1
index e4657e8b037a21aa4482eb6784fd0117f53ac5ca..4e9453fd51fbc64e4d8214559d1ca36d102b6e43 100644 (file)
@@ -17,7 +17,7 @@ void buildfiles(struct cbsfile *files) {
        compile(files[i].name);
    }
 
-   names = allocate((i + 1) * sizeof *names);
+   names = allocate(i + 1, sizeof*names);
    for (i = 0; files[i].name; ++i) names[i] = files[i].name;
 
    lflags = target->flags;
index 0c6593bf6da7c7c1dce57e90a124436c942d40c3..d77f220a57e70233ccd60c84ea56c90efaba12bb 100644 (file)
--- a/src/cbs.h
+++ b/src/cbs.h
@@ -9,6 +9,6 @@
 
 extern char **cflags, **lflags;
 
-void *allocate(size_t s);
+void *allocate(size_t num, size_t size);
 void compile(char *src);
 void load(char type, char *target, char **objs);
index 3eabce07e0d284e38f014976367560a428995187..af675e2f5811ede7e17cb2120901919ae9ca3fc8 100644 (file)
@@ -21,7 +21,7 @@ static void handleinput(void) {
    if (IsFileDropped()) {
        files = LoadDroppedFiles();
        if (xpm) free(xpm);
-       xpm = allocate(FILENAME_MAX);
+       xpm = allocate(FILENAME_MAX, sizeof*xpm);
        strcpy(xpm, files.paths[0]);
        UnloadDroppedFiles(files);
        texture = reloadtexture(xpm, mode);
index f8516ccf9f53bcc11458c041c9c3d1f1d52a3c98..63f9bba8250305e8ef9fd2cd2206e545291417c0 100644 (file)
@@ -33,7 +33,7 @@ int options(int argc, char **argv) {
        debug = 1;
        break;
    case 'f':
-       xpm = allocate(FILENAME_MAX);
+       xpm = allocate(FILENAME_MAX, sizeof*xpm);
        strcpy(xpm, optarg);
        break;
    case 'h':
index 7a2ead1a5d3042cf7c4fd69301b9115a6e8a6337..5ad3e6b423f7b5789444eff401f90b86a0e05171 100644 (file)
--- a/src/xpm.c
+++ b/src/xpm.c
@@ -47,7 +47,7 @@ static char *arrname(char *p, size_t l) {
    start = p;
    for (; !space(*p) && *p != '['; ++p, --l) if (l == 0) return NULL;
    l = p - start;
-   r = allocate(l + 1);
+   r = allocate(l + 1, sizeof*r);
    strncpy(r, start, l);
 
    return r;
@@ -158,8 +158,8 @@ static void parse(char **data, long *sizep) {
    }
 
    /* Colors */
-   chars = allocate(ncolors * cpp * sizeof*chars);
-   colors = allocate(NUMMODES * ncolors * sizeof*colors);
+   chars = allocate(ncolors * cpp, sizeof*chars);
+   colors = allocate(NUMMODES * ncolors, sizeof*colors);
    for (i = 0; i < ncolors; ++i) {
        p = data[1 + i];
        strncpy(chars + i * cpp, p, cpp);
@@ -179,7 +179,7 @@ static void parse(char **data, long *sizep) {
    }
 
    /* Pixels */
-   pixels = allocate(NUMMODES * height * width * sizeof*pixels);
+   pixels = allocate(NUMMODES * height * width, sizeof*pixels);
    j = width;
    l = 0;
    for (i = 0, pp = &data[1 + ncolors];