From 92dd6aa402fb1f125322e360207205e84e0dd4a4 Mon Sep 17 00:00:00 2001 From: Dominic Radermacher Date: Mon, 8 Apr 2019 21:56:55 +0200 Subject: [PATCH] fix several compile warnings --- Makefile.am | 2 +- build-aux/git-version-gen | 2 +- include/ptouch.h | 4 ++-- src/libptouch.c | 35 +++++++++++++++++------------------ src/ptouch-print.c | 10 ++++++++-- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Makefile.am b/Makefile.am index 23e8539..1708425 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = subdir-objects AM_CPPFLAGS= -DLOCALEDIR='"$(localedir)"' -AM_CFLAGS=-g -std=c11 -Wall -O3 -I$(top_srcdir)/include +AM_CFLAGS=-g -std=c11 -Wall -Wextra -Wunused -O3 -I$(top_srcdir)/include -fPIC SUBDIRS = po ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = config.rpath m4/ChangeLog Makefile.old diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen index b56731d..23afd31 100755 --- a/build-aux/git-version-gen +++ b/build-aux/git-version-gen @@ -1,3 +1,3 @@ #!/bin/sh -GIT_VERSION=$(git --no-pager describe --tags --dirty |sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//g') +GIT_VERSION=$(git --no-pager describe --always --tags --dirty |sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//g') echo -ne ${GIT_VERSION} diff --git a/include/ptouch.h b/include/ptouch.h index b1cc7ad..ad4e72d 100644 --- a/include/ptouch.h +++ b/include/ptouch.h @@ -77,7 +77,7 @@ typedef struct _ptouch_dev *ptouch_dev; int ptouch_open(ptouch_dev *ptdev); int ptouch_close(ptouch_dev ptdev); -int ptouch_send(ptouch_dev ptdev, uint8_t *data, int len); +int ptouch_send(ptouch_dev ptdev, uint8_t *data, size_t len); int ptouch_init(ptouch_dev ptdev); int ptouch_lf(ptouch_dev ptdev); int ptouch_ff(ptouch_dev ptdev); @@ -86,4 +86,4 @@ int ptouch_getstatus(ptouch_dev ptdev); int ptouch_getmaxwidth(ptouch_dev ptdev); int ptouch_enable_packbits(ptouch_dev ptdev); int ptouch_rasterstart(ptouch_dev ptdev); -int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, int len); +int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len); diff --git a/src/libptouch.c b/src/libptouch.c index 7883a12..4a089c8 100644 --- a/src/libptouch.c +++ b/src/libptouch.c @@ -1,7 +1,7 @@ /* libptouch - functions to help accessing a brother ptouch - Copyright (C) 2013-2017 Dominic Radermacher + Copyright (C) 2013-2019 Dominic Radermacher This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as @@ -132,19 +132,19 @@ int ptouch_close(ptouch_dev ptdev) return 0; } -int ptouch_send(ptouch_dev ptdev, uint8_t *data, int len) +int ptouch_send(ptouch_dev ptdev, uint8_t *data, size_t len) { - int r,tx; + int r, tx; - if (ptdev == NULL) { + if ((ptdev == NULL) || (len > 128)) { return -1; } - if ((r=libusb_bulk_transfer(ptdev->h, 0x02, data, len, &tx, 0)) != 0) { + if ((r=libusb_bulk_transfer(ptdev->h, 0x02, data, (int)len, &tx, 0)) != 0) { fprintf(stderr, _("write error: %s\n"), libusb_error_name(r)); return -1; } - if (tx != len) { - fprintf(stderr, _("write error: could send only %i of %i bytes\n"), tx, len); + if (tx != (int)len) { + fprintf(stderr, _("write error: could send only %i of %ld bytes\n"), tx, len); return -1; } return 0; @@ -263,25 +263,24 @@ int ptouch_getmaxwidth(ptouch_dev ptdev) return ptdev->tape_width_px; } -int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, int len) +int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len) { - uint8_t buf[70]; + uint8_t buf[64]; int rc; - if (len > ptdev->devinfo->max_px / 8) { + if (len > (size_t)(ptdev->devinfo->max_px / 8)) { return -1; } - buf[0]=0x47; if (ptdev->devinfo->flags & FLAG_RASTER_PACKBITS) { - /* Fake compression by encoding a single uncompressed run */ - buf[1] = len + 1; - buf[2] = 0; - buf[3] = len - 1; - memcpy(buf + 4, data, len); - rc = ptouch_send(ptdev, buf, len + 4); + /* Fake compression by encoding a single uncompressed run */ + buf[1] = (uint8_t)(len + 1); + buf[2] = 0; + buf[3] = (uint8_t)(len - 1); + memcpy(buf + 4, data, len); + rc = ptouch_send(ptdev, buf, len + 4); } else { - buf[1] = len; + buf[1] = (uint8_t)len; buf[2] = 0; memcpy(buf + 3, data, len); rc = ptouch_send(ptdev, buf, len + 3); diff --git a/src/ptouch-print.c b/src/ptouch-print.c index 9ef1b2b..71700bc 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -39,7 +39,10 @@ int find_fontsize(int want_px, char *font, char *text); int needed_width(char *text, char *font, int fsz); int print_img(ptouch_dev ptdev, gdImage *im); int write_png(gdImage *im, const char *file); +gdImage *img_append(gdImage *in_1, gdImage *in_2); +gdImage *img_cutmark(int tape_width); gdImage *render_text(char *font, char *line[], int lines, int tape_width); +void unsupported_printer(ptouch_dev ptdev); void usage(char *progname); int parse_args(int argc, char **argv); @@ -55,11 +58,14 @@ int fontsize=0; void rasterline_setpixel(uint8_t rasterline[16], int pixel) { - rasterline[15-(pixel/8)] |= 1<<(pixel%8); + if (pixel > 128) { + return; + } + rasterline[15-(pixel/8)] |= (uint8_t)(1<<(pixel%8)); return; } -void unsupported_printer(ptouch_dev ptdev) +void unsupported_printer(__attribute__((unused)) ptouch_dev ptdev) { printf(_("your printer unfortunately is not supported by this tool\n")); printf(_("the rasterdata a transferred in some other (unknown) format\n"));