From b8ee53a4f539501471137c8a15ec6aacddd4f8d8 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 18 Nov 2019 13:28:31 +0100 Subject: [PATCH] Fixed dll bug and macos compilation --- gallery/gallery.c | 13 ++++++------- gallery/test.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gallery/gallery.c b/gallery/gallery.c index 87abfe7..44b0089 100644 --- a/gallery/gallery.c +++ b/gallery/gallery.c @@ -34,7 +34,7 @@ struct gallery { }; static struct image_ll* find_by_name(struct gallery*, const char*); -static uint32_t ntohl (uint32_t); +static uint32_t my_ntohl (uint32_t); static struct image_ll* ll_remove(struct gallery*, struct image_ll*); const size_t INIT_CAP = 128; @@ -57,20 +57,19 @@ struct image_ll* ll_remove(struct gallery* g, struct image_ll* i) { if (i->prev) { i->prev->next = i->next; + } else { + g->images = i->next; } struct image_ll* n = i->next; free(i); g->size--; - if (g->size == 0) { - g->images = NULL; - } return n; } // inspired by https://codereview.stackexchange.com/q/149751 -uint32_t ntohl (const uint32_t nlong) { +uint32_t my_ntohl (const uint32_t nlong) { uint8_t* data = (uint8_t*) &nlong; return ((uint32_t) data[3]) | @@ -143,8 +142,8 @@ int gallery_add(struct gallery *g, char* filename) { return -2; } - new->first.width = ntohl(new->first.width); - new->first.height = ntohl(new->first.height); + new->first.width = my_ntohl(new->first.width); + new->first.height = my_ntohl(new->first.height); new->first.name = filename; new->prev = NULL; new->next = g->images; diff --git a/gallery/test.c b/gallery/test.c index e1145f1..d853032 100644 --- a/gallery/test.c +++ b/gallery/test.c @@ -5,6 +5,7 @@ #include "gallery.h" +int myfilter(char *fn, int w, int h) { return w < 640; } int main() { struct gallery *g = gallery_new(); @@ -25,7 +26,6 @@ int main() { assert(strcmp(gallery_bestfit(g, 640, 479), "480x320.png") == 0); assert(gallery_bestfit(g, 0, 0) == NULL); - int myfilter(char *fn, int w, int h) { return w < 640; } assert(gallery_filter(g, myfilter) == 1); assert(gallery_count(g) == 1);