QRCODE: check fopen() return in ZINTLOG debugging code

(ticket #181, props Stf Ortm)
CODE128: suppress gcc -Wmaybe-uninitialized false positive (Release
  only)
CLI: add "isbn" synonym; save a few bytes using `char[]` rather
  than `char *`
This commit is contained in:
gitlost 2024-02-27 13:36:13 +00:00
parent f312cdf630
commit f0d8901d9e
3 changed files with 20 additions and 19 deletions

View File

@ -131,7 +131,7 @@ static void c128_grwp(int list[2][C128_MAX], int *p_indexliste) {
* Implements rules from ISO 15417 Annex E * Implements rules from ISO 15417 Annex E
*/ */
INTERNAL void c128_dxsmooth(int list[2][C128_MAX], int *p_indexliste, const char *manual_set) { INTERNAL void c128_dxsmooth(int list[2][C128_MAX], int *p_indexliste, const char *manual_set) {
int i, j, nextshift, nextshift_i = 0; int i, j, nextshift = 0 /*Suppresses gcc -Wmaybe-uninitialized false positive*/, nextshift_i = 0;
const int indexliste = *p_indexliste; const int indexliste = *p_indexliste;
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {

View File

@ -1060,22 +1060,22 @@ static void qr_populate_grid(unsigned char *grid, const int h_size, const int v_
} }
#ifdef ZINTLOG #ifdef ZINTLOG
static int append_log(unsigned char log) { static void append_log(const unsigned char log) {
FILE *file; FILE *file;
file = fopen("zintlog.txt", "a+"); if ((file = fopen("zintlog.txt", "a+"))) {
fprintf(file, "%02X", log); fprintf(file, "%02X", log);
(void) fclose(file); (void) fclose(file);
return 0; }
} }
static int write_log(char log[]) { static void write_log(const char log[]) {
FILE *file; FILE *file;
file = fopen("zintlog.txt", "a+"); if ((file = fopen("zintlog.txt", "a+"))) {
fprintf(file, "%s\n", log); /*writes*/ fprintf(file, "%s\n", log); /*writes*/
(void) fclose(file); (void) fclose(file);
return 0; }
} }
#endif #endif

View File

@ -379,8 +379,8 @@ static void to_lower(char source[]) {
/* Return symbology id if `barcode_name` a barcode name */ /* Return symbology id if `barcode_name` a barcode name */
static int get_barcode_name(const char *barcode_name) { static int get_barcode_name(const char *barcode_name) {
struct name { const int symbology; const char *n; }; /* Must be sorted for binary search to work */
static const struct name names[] = { /* Must be sorted for binary search to work */ static const struct { int symbology; const char *n; } names[] = {
{ BARCODE_C25LOGIC, "2of5datalogic" }, /* Synonym */ { BARCODE_C25LOGIC, "2of5datalogic" }, /* Synonym */
{ BARCODE_C25IATA, "2of5iata" }, /* Synonym */ { BARCODE_C25IATA, "2of5iata" }, /* Synonym */
{ BARCODE_C25IND, "2of5ind" }, /* Synonym */ { BARCODE_C25IND, "2of5ind" }, /* Synonym */
@ -534,6 +534,7 @@ static int get_barcode_name(const char *barcode_name) {
{ BARCODE_C25IND, "industrialcode2of5" }, /* Synonym */ { BARCODE_C25IND, "industrialcode2of5" }, /* Synonym */
{ BARCODE_C25INTER, "interleaved2of5" }, /* Synonym */ { BARCODE_C25INTER, "interleaved2of5" }, /* Synonym */
{ BARCODE_C25INTER, "interleavedcode2of5" }, /* Synonym */ { BARCODE_C25INTER, "interleavedcode2of5" }, /* Synonym */
{ BARCODE_ISBNX, "isbn" }, /* Synonym */
{ BARCODE_ISBNX, "isbnx" }, { BARCODE_ISBNX, "isbnx" },
{ BARCODE_ITF14, "itf14" }, { BARCODE_ITF14, "itf14" },
{ BARCODE_JAPANPOST, "japanpost" }, { BARCODE_JAPANPOST, "japanpost" },
@ -636,7 +637,7 @@ static int get_barcode_name(const char *barcode_name) {
/* Whether `filetype` supported by Zint. Sets `png_refused` if `no_png` and PNG requested */ /* Whether `filetype` supported by Zint. Sets `png_refused` if `no_png` and PNG requested */
static int supported_filetype(const char *filetype, const int no_png, int *png_refused) { static int supported_filetype(const char *filetype, const int no_png, int *png_refused) {
static const char *filetypes[] = { static const char filetypes[][4] = {
"bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt", "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt",
}; };
char lc_filetype[4] = {0}; char lc_filetype[4] = {0};
@ -702,7 +703,7 @@ static void set_extension(char *file, const char *filetype) {
/* Whether `filetype` is raster type */ /* Whether `filetype` is raster type */
static int is_raster(const char *filetype, const int no_png) { static int is_raster(const char *filetype, const int no_png) {
static const char *raster_filetypes[] = { static const char raster_filetypes[][4] = {
"bmp", "gif", "pcx", "png", "tif", "bmp", "gif", "pcx", "png", "tif",
}; };
int i; int i;
@ -727,7 +728,7 @@ static int is_raster(const char *filetype, const int no_png) {
} }
/* Helper for `validate_scalexdimdp()` to search for units, returning -2 on error, -1 if not found, else index */ /* Helper for `validate_scalexdimdp()` to search for units, returning -2 on error, -1 if not found, else index */
static int validate_units(char *buf, const char *units[], int units_size) { static int validate_units(char *buf, const char units[][5], int units_size) {
int i; int i;
char *unit; char *unit;
@ -749,8 +750,8 @@ static int validate_units(char *buf, const char *units[], int units_size) {
/* Parse and validate argument "xdim[,resolution]" to "--scalexdimdp" */ /* Parse and validate argument "xdim[,resolution]" to "--scalexdimdp" */
static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_dpmm) { static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_dpmm) {
static const char *x_units[] = { "mm", "in" }; static const char x_units[][5] = { "mm", "in" };
static const char *r_units[] = { "dpmm", "dpi" }; static const char r_units[][5] = { "dpmm", "dpi" };
char x_buf[7 + 1 + 4 + 1] = {0}; /* Allow for 7 digits + dot + 4-char unit + NUL */ char x_buf[7 + 1 + 4 + 1] = {0}; /* Allow for 7 digits + dot + 4-char unit + NUL */
char r_buf[7 + 1 + 4 + 1] = {0}; /* As above */ char r_buf[7 + 1 + 4 + 1] = {0}; /* As above */
int units_i; /* For `validate_units()` */ int units_i; /* For `validate_units()` */
@ -1406,7 +1407,7 @@ static int do_exit(int error_number) {
return error_number; /* Not reached */ return error_number; /* Not reached */
} }
typedef struct { char *arg; int opt; } arg_opt; typedef struct { const char *arg; int opt; } arg_opt;
int main(int argc, char **argv) { int main(int argc, char **argv) {
struct zint_symbol *my_symbol; struct zint_symbol *my_symbol;