From cb8b300a174baba50c4e0314d63c66d4a7bbc825 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Wed, 29 Mar 2023 14:58:35 +0200 Subject: [PATCH 1/7] fix for codes with starting FNC3 that returns invalid characters in string --- code128.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/code128.c b/code128.c index 32de7cc..97e0560 100644 --- a/code128.c +++ b/code128.c @@ -296,8 +296,9 @@ static int code128_do_a_step(struct code128_step *base, int prev_ix, int ix) return 0; step->code = code128a_ascii_to_code(value); - if (step->code < 0) + if (step->code < 0) { return 0; + } step->prev_ix = prev_ix; step->next_input = previous_step->next_input + 1; @@ -320,8 +321,9 @@ static int code128_do_b_step(struct code128_step *base, int prev_ix, int ix) return 0; step->code = code128b_ascii_to_code(value); - if (step->code < 0) + if (step->code < 0) { return 0; + } step->prev_ix = prev_ix; step->next_input = previous_step->next_input + 1; @@ -344,8 +346,9 @@ static int code128_do_c_step(struct code128_step *base, int prev_ix, int ix) return 0; step->code = code128c_ascii_to_code(previous_step->next_input); - if (step->code < 0) + if (step->code < 0) { return 0; + } step->prev_ix = prev_ix; step->next_input = previous_step->next_input + 1; @@ -380,8 +383,9 @@ static void code128_do_step(struct code128_state *state) struct code128_step *step = &state->steps[state->current_ix]; if (*step->next_input == 0) { // Done, so see if we have a new shortest encoding. - if ((step->len < state->maxlength) || - (state->best_ix < 0 && step->len == state->maxlength)) { + // Fix for some FNC3 starting codes + if ((step->len - CODE128_CHAR_LEN < state->maxlength) || + (state->best_ix < 0 && step->len - CODE128_CHAR_LEN == state->maxlength)) { state->best_ix = state->current_ix; // Update maxlength to avoid considering anything longer @@ -483,7 +487,8 @@ size_t ADDCALL code128_encode_raw(const char *s, char *out, size_t maxlength) } while (state.current_ix != state.todo_ix); // If no best_step, then fail. - if (state.best_ix < 0) { + if (state.best_ix < 0) + { free(state.steps); return 0; } From 6fac437da0a756829eada35720cc2959e58e7582 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Wed, 29 Mar 2023 14:59:12 +0200 Subject: [PATCH 2/7] bump to version 1.1 and versioning windows DLL as it is on linux --- Makefile | 2 +- Makefile_windows | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6f31ea6..42cdbd1 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CFLAGS ?= -O2 -Wall -Wextra -Wno-implicit-fallthrough MAJOR := 1 -MINOR := 0 +MINOR := 1 NAME := code128 VERSION := $(MAJOR).$(MINOR) diff --git a/Makefile_windows b/Makefile_windows index 4a29384..f189de4 100644 --- a/Makefile_windows +++ b/Makefile_windows @@ -1,5 +1,8 @@ # This Makefile will build a DLL and an application which makes use of the DLL. +MAJOR := 1 +MINOR := 1 +VERSION := $(MAJOR).$(MINOR) DLL_NAME := code128 EXE_NAME := code128png @@ -23,7 +26,7 @@ EXE_LDFLAGS += $(foreach library,$(CODE128PNG_LIBRARIES),-l$(library)) # Names of tools to use when building CC = cc -DLL = lib$(DLL_NAME)-$(ARCH).dll +DLL = lib$(DLL_NAME)_v$(VERSION)-$(ARCH).dll EXE = $(EXE_NAME)-$(ARCH).exe # Compiler flags @@ -57,7 +60,7 @@ $(DLL_NAME).o: $(DLL_NAME).c $(DLL_NAME).h ${DLL}: ${DLL_OBJS} ${CC} -o "$@" ${DLL_OBJS} ${DLL_LDFLAGS} -# Buld the executable +# Build the executable ${EXE}: ${EXE_OBJS} ${CC} ${EXE_CFLAGS} -o "$@" ${EXE_OBJS} ${EXE_LDFLAGS} From 01e96ac8dc33545761d78da7923fd3fd4c1b373e Mon Sep 17 00:00:00 2001 From: gpongelli Date: Wed, 29 Mar 2023 15:09:19 +0200 Subject: [PATCH 3/7] fix: warning comparison integer signedness --- code128.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code128.c b/code128.c index 97e0560..d32250b 100644 --- a/code128.c +++ b/code128.c @@ -384,8 +384,9 @@ static void code128_do_step(struct code128_state *state) if (*step->next_input == 0) { // Done, so see if we have a new shortest encoding. // Fix for some FNC3 starting codes - if ((step->len - CODE128_CHAR_LEN < state->maxlength) || - (state->best_ix < 0 && step->len - CODE128_CHAR_LEN == state->maxlength)) { + size_t step_len = step->len - CODE128_CHAR_LEN; + if ((step_len < state->maxlength) || + (state->best_ix < 0 && step_len == state->maxlength)) { state->best_ix = state->current_ix; // Update maxlength to avoid considering anything longer From 306813a7be7691557889a7651e2cbc711cf792ca Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 30 Mar 2023 13:54:48 +0200 Subject: [PATCH 4/7] implicit fallthrough warning --- code128.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code128.c b/code128.c index d32250b..e81e4ad 100644 --- a/code128.c +++ b/code128.c @@ -215,6 +215,7 @@ static signed char code128_switch_code(char from_mode, char to_mode) case CODE128_MODE_C: return 99; } + break; case CODE128_MODE_B: switch (to_mode) { @@ -223,6 +224,7 @@ static signed char code128_switch_code(char from_mode, char to_mode) case CODE128_MODE_C: return 99; } + break; case CODE128_MODE_C: switch (to_mode) { @@ -231,6 +233,7 @@ static signed char code128_switch_code(char from_mode, char to_mode) case CODE128_MODE_A: return 101; } + break; } assert(0); // Invalid mode switch From 1c2b58caf5b4d32fe6545b8c84e7518f6e914d10 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 30 Mar 2023 13:55:44 +0200 Subject: [PATCH 5/7] type-limits warning --- code128.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code128.c b/code128.c index e81e4ad..d201248 100644 --- a/code128.c +++ b/code128.c @@ -244,7 +244,7 @@ static signed char code128a_ascii_to_code(char value) { if (value >= ' ' && value <= '_') return value - ' '; - else if (value >= 0 && value < ' ') + else if (value < ' ') return value + 64; else if (value == CODE128_FNC1) return 102; From 8dcbd26e62f9b986d84f3ec5cd32bbd2219b9deb Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 30 Mar 2023 13:56:21 +0200 Subject: [PATCH 6/7] fix for FNC3 starting character both on ARM and x86 --- code128.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code128.c b/code128.c index d201248..0835039 100644 --- a/code128.c +++ b/code128.c @@ -260,7 +260,8 @@ static signed char code128a_ascii_to_code(char value) static signed char code128b_ascii_to_code(char value) { - if (value >= 32) // value <= 127 is implied + /* value <= 127 is required to work both on x86 and on ARM. */ + if ((value >= 32) && (value <= 127)) return value - 32; else if (value == CODE128_FNC1) return 102; From e985b812e6ba0bd80157a85b7735eb9273b255ee Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 30 Mar 2023 15:31:15 +0200 Subject: [PATCH 7/7] revert a change that breaks some labels on windows --- code128.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code128.c b/code128.c index 0835039..e11d099 100644 --- a/code128.c +++ b/code128.c @@ -244,7 +244,7 @@ static signed char code128a_ascii_to_code(char value) { if (value >= ' ' && value <= '_') return value - ' '; - else if (value < ' ') + else if (value >= 0 && value < ' ') return value + 64; else if (value == CODE128_FNC1) return 102; @@ -352,7 +352,7 @@ static int code128_do_c_step(struct code128_step *base, int prev_ix, int ix) step->code = code128c_ascii_to_code(previous_step->next_input); if (step->code < 0) { return 0; - } + } step->prev_ix = prev_ix; step->next_input = previous_step->next_input + 1;