diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-02-02 17:13:01 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-02-02 17:13:01 +0100 |
commit | ffa8801644a7d53cc1c785e3450f794c07a14eb0 (patch) | |
tree | 8d72a18a9a08b9151d12badcb1c78ce06a059f62 /frontend/scanimage.c | |
parent | 1687222e1b9e74c89cafbb5910e72d8ec7bfd40f (diff) |
New upstream version 1.0.29upstream/1.0.29
Diffstat (limited to 'frontend/scanimage.c')
-rw-r--r-- | frontend/scanimage.c | 84 |
1 files changed, 35 insertions, 49 deletions
diff --git a/frontend/scanimage.c b/frontend/scanimage.c index 6906f90..ae65ebf 100644 --- a/frontend/scanimage.c +++ b/frontend/scanimage.c @@ -32,6 +32,7 @@ #include <assert.h> #include "lgetopt.h" +#include <inttypes.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -204,51 +205,30 @@ auth_callback (SANE_String_Const resource, if ((strlen (tmp) > 0) && (tmp[strlen (tmp) - 1] == '\r')) tmp[strlen (tmp) - 1] = 0; - if (strchr (tmp, ':') != NULL) + char *colon1 = strchr (tmp, ':'); + if (colon1 != NULL) { + char *tmp_username = tmp; + *colon1 = '\0'; - if (strchr (strchr (tmp, ':') + 1, ':') != NULL) + char *colon2 = strchr (colon1 + 1, ':'); + if (colon2 != NULL) { + char *tmp_password = colon1 + 1; + *colon2 = '\0'; - if ((strncmp - (strchr (strchr (tmp, ':') + 1, ':') + 1, - resource, len) == 0) - && - ((int) strlen - (strchr (strchr (tmp, ':') + 1, ':') + 1) == - len)) + if ((strncmp (colon2 + 1, resource, len) == 0) + && ((int) strlen (colon2 + 1) == len)) { - - if ((strchr (tmp, ':') - tmp) < - SANE_MAX_USERNAME_LEN) - { - - if ((strchr (strchr (tmp, ':') + 1, ':') - - (strchr (tmp, ':') + 1)) < - SANE_MAX_PASSWORD_LEN) - { - - strncpy (username, tmp, - strchr (tmp, ':') - tmp); - - username[strchr (tmp, ':') - tmp] = 0; - - strncpy (password, - strchr (tmp, ':') + 1, - strchr (strchr (tmp, ':') + 1, - ':') - - (strchr (tmp, ':') + 1)); - password[strchr - (strchr (tmp, ':') + 1, - ':') - (strchr (tmp, - ':') + 1)] = - 0; - - query_user = 0; - break; - } - } - + if ((strlen (tmp_username) < SANE_MAX_USERNAME_LEN) && + (strlen (tmp_password) < SANE_MAX_PASSWORD_LEN)) + { + strncpy (username, tmp_username, SANE_MAX_USERNAME_LEN); + strncpy (password, tmp_password, SANE_MAX_PASSWORD_LEN); + + query_user = 0; + break; + } } } } @@ -1317,7 +1297,8 @@ advance (Image * image) static SANE_Status scan_it (FILE *ofp) { - int i, len, first_frame = 1, offset = 0, must_buffer = 0, hundred_percent; + int i, len, first_frame = 1, offset = 0, must_buffer = 0; + uint64_t hundred_percent = 0; SANE_Byte min = 0xff, max = 0; SANE_Parameters parm; SANE_Status status; @@ -1325,7 +1306,7 @@ scan_it (FILE *ofp) static const char *format_name[] = { "gray", "RGB", "red", "green", "blue" }; - SANE_Word total_bytes = 0, expected_bytes; + uint64_t total_bytes = 0, expected_bytes; SANE_Int hang_over = -1; #ifdef HAVE_LIBPNG int pngrow = 0; @@ -1486,7 +1467,7 @@ scan_it (FILE *ofp) offset = parm.format - SANE_FRAME_RED; image.x = image.y = 0; } - hundred_percent = parm.bytes_per_line * parm.lines + hundred_percent = ((uint64_t)parm.bytes_per_line) * parm.lines * ((parm.format == SANE_FRAME_RGB || parm.format == SANE_FRAME_GRAY) ? 1:3); while (1) @@ -1498,7 +1479,12 @@ scan_it (FILE *ofp) if (progr > 100.) progr = 100.; if (progress) - fprintf (stderr, "Progress: %3.1f%%\r", progr); + { + if (parm.lines >= 0) + fprintf(stderr, "Progress: %3.1f%%\r", progr); + else + fprintf(stderr, "Progress: (unknown)\r"); + } if (status != SANE_STATUS_GOOD) { @@ -1760,7 +1746,7 @@ cleanup: free (image.data); - expected_bytes = parm.bytes_per_line * parm.lines * + expected_bytes = ((uint64_t)parm.bytes_per_line) * parm.lines * ((parm.format == SANE_FRAME_RGB || parm.format == SANE_FRAME_GRAY) ? 1 : 3); if (parm.lines < 0) @@ -1769,10 +1755,10 @@ cleanup: { fprintf (stderr, "%s: WARNING: read more data than announced by backend " - "(%u/%u)\n", prog_name, total_bytes, expected_bytes); + "(%" PRIu64 "/%" PRIu64 ")\n", prog_name, total_bytes, expected_bytes); } else if (verbose) - fprintf (stderr, "%s: read %u bytes in total\n", prog_name, total_bytes); + fprintf (stderr, "%s: read %" PRIu64 " bytes in total\n", prog_name, total_bytes); return status; } @@ -2260,15 +2246,15 @@ main (int argc, char **argv) if (defdevname) printf ("default device is `%s'\n", defdevname); scanimage_exit (0); + break; } - case 'V': printf ("scanimage (%s) %s; backend version %d.%d.%d\n", PACKAGE, VERSION, SANE_VERSION_MAJOR (version_code), SANE_VERSION_MINOR (version_code), SANE_VERSION_BUILD (version_code)); scanimage_exit (0); - + break; default: break; /* ignore device specific options for now */ } |