diff --git a/backend/artec.c b/backend/artec.c index 2ba8d6dad..395b4f1b9 100644 --- a/backend/artec.c +++ b/backend/artec.c @@ -1999,8 +1999,8 @@ attach (const char *devname, ARTEC_Device ** devp) DBG (6, "Found BlackWidow BW4800SP scanner, setting up like AT3\n"); /* setup the vendor and product to mimic the Artec/Ultima AT3 */ - strncpy (result + 8, "ULTIMA", 6); - strncpy (result + 16, "AT3 ", 16); + memcpy (result + 8, "ULTIMA", 6); + memcpy (result + 16, "AT3 ", 16); } /* @@ -2013,8 +2013,8 @@ attach (const char *devname, ARTEC_Device ** devp) DBG (6, "Found Plustek 19200S scanner, setting up like AM12S\n"); /* setup the vendor and product to mimic the Artec/Ultima AM12S */ - strncpy (result + 8, "ULTIMA", 6); - strncpy (result + 16, "AM12S ", 16); + memcpy (result + 8, "ULTIMA", 6); + memcpy (result + 16, "AM12S ", 16); } /* diff --git a/backend/as6e.c b/backend/as6e.c index 37a6d3b68..47d8c9081 100644 --- a/backend/as6e.c +++ b/backend/as6e.c @@ -797,7 +797,6 @@ check_for_driver (const char *devname) struct stat statbuf; mode_t modes; char *path; - char fullname[NAMESIZE]; char dir[NAMESIZE]; int count = 0, offset = 0, valid; @@ -806,7 +805,6 @@ check_for_driver (const char *devname) return 0; while (path[count] != '\0') { - memset (fullname, '\0', sizeof (fullname)); memset (dir, '\0', sizeof (dir)); valid = 1; while ((path[count] != ':') && (path[count] != '\0')) @@ -819,19 +817,19 @@ check_for_driver (const char *devname) count++; } if (valid == 1) - { - /* use sizeof(fullname)-1 to make sure there is at least one padded null byte */ - strncpy (fullname, dir, sizeof(fullname)-1); - /* take into account that fullname already contains non-null bytes */ - strncat (fullname, "/", sizeof(fullname)-strlen(fullname)-1); - strncat (fullname, devname, sizeof(fullname)-strlen(fullname)-1); - if (!stat (fullname, &statbuf)) - { - modes = statbuf.st_mode; - if (S_ISREG (modes)) - return (1); /* found as6edriver */ - } - } + { + char fullname[NAMESIZE]; + int len = snprintf(fullname, sizeof(fullname), "%s/%s", dir, devname); + if ((len > 0) && (len <= (int)sizeof(fullname))) + { + if (!stat (fullname, &statbuf)) + { + modes = statbuf.st_mode; + if (S_ISREG (modes)) + return (1); /* found as6edriver */ + } + } + } if (path[count] == '\0') return (0); /* end of path --no driver found */ count++; diff --git a/backend/epjitsu.c b/backend/epjitsu.c index bee4310ec..714bc0b97 100644 --- a/backend/epjitsu.c +++ b/backend/epjitsu.c @@ -349,10 +349,21 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) continue; if ((strncmp ("firmware", lp, 8) == 0) && isspace (lp[8])) { + size_t firmware_len; + lp += 8; lp = sanei_config_skip_whitespace (lp); DBG (15, "sane_get_devices: firmware '%s'\n", lp); - strncpy((char *)global_firmware_filename,lp,PATH_MAX); + + firmware_len = strlen(lp); + if (firmware_len > sizeof(global_firmware_filename) - 1) + { + DBG (5, "sane_get_devices: firmware file too long. ignoring '%s'\n", lp); + } + else + { + strcpy((char *)global_firmware_filename, lp); + } } else if ((strncmp ("usb", lp, 3) == 0) && isspace (lp[3])) { DBG (15, "sane_get_devices: looking for '%s'\n", lp); diff --git a/backend/escl/escl_devices.c b/backend/escl/escl_devices.c index 8adf2fdff..20ded281c 100644 --- a/backend/escl/escl_devices.c +++ b/backend/escl/escl_devices.c @@ -37,13 +37,26 @@ static AvahiSimplePoll *simple_poll = NULL; /** - * \fn static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name, - * const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void *userdata) - * \brief Callback function that will check if the selected scanner follows the escl protocol or not. + * \fn static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED + * AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, + * AvahiResolverEvent event, const char *name, + * const char *type, const char *domain, const char *host_name, + * const AvahiAddress *address, uint16_t port, + * AvahiStringList *txt, AvahiLookupResultFlags flags, + * void *userdata) + * \brief Callback function that will check if the selected scanner follows the escl + * protocol or not. */ static void -resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name, - const char __sane_unused__ *type, const char __sane_unused__ *domain, const char __sane_unused__ *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags __sane_unused__ flags, void __sane_unused__ *userdata) +resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, + AVAHI_GCC_UNUSED AvahiProtocol protocol, + AvahiResolverEvent event, const char *name, + const char __sane_unused__ *type, + const char __sane_unused__ *domain, + const char __sane_unused__ *host_name, + const AvahiAddress *address, uint16_t port, AvahiStringList *txt, + AvahiLookupResultFlags __sane_unused__ flags, + void __sane_unused__ *userdata) { char a[AVAHI_ADDRESS_STR_MAX], *t; assert(r); @@ -59,13 +72,20 @@ resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interfac } /** - * \fn static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, + * \fn static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, + * AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, + * const char *type, const char *domain, * AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata) - * \brief Callback function that will browse tanks to 'avahi' the scanners connected in network. + * \brief Callback function that will browse tanks to 'avahi' the scanners + * connected in network. */ static void -browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, - AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata) +browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, + AvahiProtocol protocol, AvahiBrowserEvent event, + const char *name, const char *type, + const char *domain, + AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, + void* userdata) { AvahiClient *c = userdata; assert(b); @@ -74,7 +94,10 @@ browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol pr avahi_simple_poll_quit(simple_poll); return; case AVAHI_BROWSER_NEW: - if (!(avahi_service_resolver_new(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c))) + if (!(avahi_service_resolver_new(c, interface, protocol, name, + type, domain, + AVAHI_PROTO_UNSPEC, 0, + resolve_callback, c))) break; case AVAHI_BROWSER_REMOVE: break; @@ -87,12 +110,15 @@ browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol pr } /** - * \fn static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *userdata) - * \brief Callback Function that quit if it doesn't find a connected scanner, possible thanks the "Hello Protocol". + * \fn static void client_callback(AvahiClient *c, AvahiClientState state, + * AVAHI_GCC_UNUSED void *userdata) + * \brief Callback Function that quit if it doesn't find a connected scanner, + * possible thanks the "Hello Protocol". * --> Waiting for a answer by the scanner to continue the avahi process. */ static void -client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *userdata) +client_callback(AvahiClient *c, AvahiClientState state, + AVAHI_GCC_UNUSED void *userdata) { assert(c); if (state == AVAHI_CLIENT_FAILURE) @@ -101,7 +127,8 @@ client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *u /** * \fn ESCL_Device *escl_devices(SANE_Status *status) - * \brief Function that calls all the avahi functions and then, recovers the connected eSCL devices. + * \brief Function that calls all the avahi functions and then, recovers the + * connected eSCL devices. * This function is called in the 'sane_get_devices' function. * * \return NULL (the eSCL devices found) @@ -119,19 +146,27 @@ escl_devices(SANE_Status *status) *status = SANE_STATUS_INVAL; goto fail; } - client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error); + client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, + client_callback, NULL, &error); if (!client) { fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); *status = SANE_STATUS_INVAL; goto fail; } - if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_uscan._tcp", NULL, 0, browse_callback, client))) { - fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); + if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, + AVAHI_PROTO_UNSPEC, "_uscan._tcp", + NULL, 0, browse_callback, client))) { + fprintf(stderr, "Failed to create service browser: %s\n", + avahi_strerror(avahi_client_errno(client))); *status = SANE_STATUS_INVAL; goto fail; } - if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_uscans._tcp", NULL, 0, browse_callback, client))) { - fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); + if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, + AVAHI_PROTO_UNSPEC, + "_uscans._tcp", NULL, 0, + browse_callback, client))) { + fprintf(stderr, "Failed to create service browser: %s\n", + avahi_strerror(avahi_client_errno(client))); *status = SANE_STATUS_INVAL; goto fail; } diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index e300c73c6..7c25168d1 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -513,15 +513,7 @@ void sanei_genesys_init_shading_data(Genesys_Device* dev, const Genesys_Sensor& int channels; int i; - /* these models don't need to init shading data due to the use of specific send shading data - function */ - if (dev->model->sensor_id==SensorId::CCD_KVSS080 || - dev->model->sensor_id==SensorId::CCD_G4050 || - dev->model->sensor_id==SensorId::CCD_HP_4850C || - dev->model->sensor_id==SensorId::CCD_CANON_4400F || - dev->model->sensor_id==SensorId::CCD_CANON_8400F || - dev->cmd_set->has_send_shading_data()) - { + if (dev->cmd_set->has_send_shading_data()) { return; } @@ -1086,7 +1078,11 @@ void scanner_move_back_home(Genesys_Device& dev, bool wait_until_home) if (dev.model->model_id == ModelId::CANON_LIDE_210) { // move the head back a little first - scanner_move(dev, dev.model->default_method, 20, Direction::BACKWARD); + if (dev.is_head_pos_known(ScanHeadId::PRIMARY) && + dev.head_pos(ScanHeadId::PRIMARY) > 30) + { + scanner_move(dev, dev.model->default_method, 20, Direction::BACKWARD); + } } Genesys_Register_Set local_reg = dev.reg; @@ -3434,8 +3430,6 @@ static void genesys_read_ordered_data(Genesys_Device* dev, SANE_Byte* destinatio throw SaneException("read is not active"); } - debug_dump(DBG_info, dev->session.params); - DBG(DBG_info, "%s: frontend requested %zu bytes\n", __func__, *len); DBG(DBG_info, "%s: bytes_to_read=%zu, total_bytes_read=%zu\n", __func__, dev->total_bytes_to_read, dev->total_bytes_read); diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index 2b2a5a3fc..054f1ef0b 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -169,9 +169,10 @@ gl124_init_registers (Genesys_Device * dev) dev->reg.init_reg(0x6d, 0x00); dev->reg.init_reg(0x71, 0x1f); } - dev->reg.init_reg(0x70, 0x00); - dev->reg.init_reg(0x72, 0x08); - dev->reg.init_reg(0x73, 0x0a); + dev->reg.init_reg(0x70, 0x00); // SENSOR_DEF + dev->reg.init_reg(0x71, 0x08); // SENSOR_DEF + dev->reg.init_reg(0x72, 0x08); // SENSOR_DEF + dev->reg.init_reg(0x73, 0x0a); // SENSOR_DEF // CKxMAP dev->reg.init_reg(0x74, 0x00); // SENSOR_DEF @@ -1628,7 +1629,8 @@ SensorExposure CommandSetGl124::led_calibration(Genesys_Device* dev, const Genes /* we accept +- 2% delta from target */ if(abs(avg[i]-target)>target/50) { - exp[i]=(exp[i]*target)/avg[i]; + float prev_weight = 0.5; + exp[i] = exp[i] * prev_weight + ((exp[i] * target) / avg[i]) * (1 - prev_weight); acceptable = false; } } diff --git a/backend/genesys/gl124_registers.h b/backend/genesys/gl124_registers.h index 1daa97406..9b42084a1 100644 --- a/backend/genesys/gl124_registers.h +++ b/backend/genesys/gl124_registers.h @@ -228,9 +228,9 @@ static constexpr RegAddr REG_0x80 = 0x80; static constexpr RegAddr REG_0x81 = 0x81; static constexpr RegAddr REG_0xA0 = 0xa0; -static constexpr RegMask REG_0xA0_FSTPSEL = 0x28; +static constexpr RegMask REG_0xA0_FSTPSEL = 0x38; static constexpr RegShift REG_0xA0S_FSTPSEL = 3; -static constexpr RegMask REG_0xA0_STEPSEL = 0x03; +static constexpr RegMask REG_0xA0_STEPSEL = 0x07; static constexpr RegShift REG_0xA0S_STEPSEL = 0; static constexpr RegAddr REG_0xA1 = 0xa1; diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index 16614b60e..04ee85ec2 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -1406,6 +1406,8 @@ static void end_scan_impl(Genesys_Device* dev, Genesys_Register_Set* reg, bool c return; } + dev->interface->sleep_ms(100); + if (check_stop) { for (unsigned i = 0; i < wait_limit_seconds * 10; i++) { if (scanner_is_motor_stopped(*dev)) { diff --git a/backend/genesys/image_pipeline.cpp b/backend/genesys/image_pipeline.cpp index aedefa77c..c01b7f487 100644 --- a/backend/genesys/image_pipeline.cpp +++ b/backend/genesys/image_pipeline.cpp @@ -220,7 +220,7 @@ ImagePipelineNodeDesegment::ImagePipelineNodeDesegment(ImagePipelineNode& source segment_pixels_{segment_pixels}, interleaved_lines_{interleaved_lines}, pixels_per_chunk_{pixels_per_chunk}, - buffer_{get_row_bytes()} + buffer_{source_.get_row_bytes()} { DBG_HELPER_ARGS(dbg, "segment_count=%zu, segment_size=%zu, interleaved_lines=%zu, " "pixels_per_shunk=%zu", segment_order.size(), segment_pixels, diff --git a/backend/genesys/tables_sensor.cpp b/backend/genesys/tables_sensor.cpp index 09295d303..21a90fa69 100644 --- a/backend/genesys/tables_sensor.cpp +++ b/backend/genesys/tables_sensor.cpp @@ -1613,7 +1613,8 @@ void genesys_init_sensor_tables() }; CustomSensorSettings custom_settings[] = { - { { 75, 100, 150, 200 }, 2848, { 410, 275, 203 }, 5136, std::vector{}, { + // Note: Windows driver uses 1424 lperiod and enables dummy line (0x17) + { { 75, 100, 150, 200 }, 2848, { 304, 203, 180 }, 5136, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x0a }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1623,7 +1624,8 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 300, 400 }, 1424, { 410, 275, 203 }, 5136, std::vector{}, { + // Note: Windows driver uses 788 lperiod and enables dummy line (0x17) + { { 300, 400 }, 1424, { 304, 203, 180 }, 5136, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x0a }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1633,7 +1635,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 600 }, 1432, { 410, 275, 203 }, 5136, std::vector{}, { + { { 600 }, 1432, { 492, 326, 296 }, 5136, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x0a }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1643,7 +1645,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 1200 }, 2712, { 746, 478, 353 }, 5136, { 0, 1 }, { + { { 1200 }, 2712, { 935, 592, 538 }, 5136, { 0, 1 }, { { 0x16, 0x10 }, { 0x17, 0x08 }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1653,7 +1655,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 2400 }, 5280, { 1417, 909, 643 }, 5136, { 0, 2, 1, 3 }, { + { { 2400 }, 5280, { 1777, 1125, 979 }, 5136, { 0, 2, 1, 3 }, { { 0x16, 0x10 }, { 0x17, 0x06 }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1663,7 +1665,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 4800 }, 10416, { 2692, 1728, 1221 }, 5136, { 0, 2, 4, 6, 1, 3, 5, 7 }, { + { { 4800 }, 10416, { 3377, 2138, 1780 }, 5136, { 0, 2, 4, 6, 1, 3, 5, 7 }, { { 0x16, 0x10 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1816,7 +1818,7 @@ void genesys_init_sensor_tables() }; CustomSensorSettings custom_settings[] = { - { { 75, 100, 150, 200 }, 2848, { 410, 275, 203 }, 5136, std::vector{}, { + { { 75, 100, 150, 200 }, 2304, { 423, 294, 242 }, 5136, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x0a }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1826,7 +1828,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 300 }, 1424, { 410, 275, 203 }, 5136, std::vector{}, { + { { 300 }, 1728, { 423, 294, 242 }, 5136, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x0a }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1836,7 +1838,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 600 }, 1432, { 410, 275, 203 }, 5136, std::vector{}, { + { { 600 }, 1432, { 423, 294, 242 }, 5136, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x0a }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1846,7 +1848,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, }, }, - { { 1200 }, 2712, { 746, 478, 353 }, 5136, {0, 1}, { + { { 1200 }, 2712, { 791, 542, 403 }, 5136, {0, 1}, { { 0x16, 0x10 }, { 0x17, 0x08 }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -1856,7 +1858,7 @@ void genesys_init_sensor_tables() { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, } }, - { { 2400 }, 5280, { 1417, 909, 643 }, 5136, {0, 2, 1, 3}, { + { { 2400 }, 5280, { 1504, 1030, 766 }, 5136, {0, 2, 1, 3}, { { 0x16, 0x10 }, { 0x17, 0x06 }, { 0x18, 0x00 }, { 0x19, 0xff }, { 0x1a, 0x34 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x04 }, { 0x52, 0x03 }, { 0x53, 0x07 }, { 0x54, 0x00 }, { 0x55, 0x00 }, @@ -2806,15 +2808,14 @@ void genesys_init_sensor_tables() }; CustomSensorSettings custom_settings[] = { - { { 75, 100, 150, 300 }, 2768, { 388, 574, 393 }, std::vector{}, { - // { 0x16, 0x00 }, // FIXME: check if default value is different + { { 75, 100, 150 }, 4608, { 462, 609, 453 }, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x0c }, { 0x52, 0x00 }, { 0x53, 0x02 }, { 0x54, 0x04 }, { 0x55, 0x06 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x1a }, { 0x5b, 0x00 }, { 0x5c, 0xc0 }, { 0x61, 0x20 }, - // { 0x70, 0x00 }, // FIXME: check if default value is different + { 0x70, 0x06 }, { 0x71, 0x08 }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x1e }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x9f }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, @@ -2824,15 +2825,31 @@ void genesys_init_sensor_tables() { 0x98, 0x21 }, } }, - { { 600 }, 5360, { 388, 574, 393 }, std::vector{}, { - // { 0x16, 0x00 }, // FIXME: check if default value is different + { { 300 }, 4608, { 462, 609, 453 }, std::vector{}, { { 0x16, 0x10 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x0a }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x0c }, { 0x52, 0x00 }, { 0x53, 0x02 }, { 0x54, 0x04 }, { 0x55, 0x06 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x1a }, { 0x5b, 0x00 }, { 0x5c, 0xc0 }, { 0x61, 0x20 }, - // { 0x70, 0x00 }, // FIXME: check if default value is different + { 0x70, 0x06 }, { 0x71, 0x08 }, { 0x72, 0x08 }, { 0x73, 0x0a }, + { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x1e }, + { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x9f }, + { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, + { 0x88, 0x00 }, { 0x89, 0x65 }, + { 0x93, 0x00 }, { 0x94, 0x0a }, { 0x95, 0x18 }, + { 0x96, 0x00 }, { 0x97, 0x9a }, + { 0x98, 0x21 }, + } + }, + { { 600 }, 5360, { 823, 1117, 805 }, std::vector{}, { + { 0x16, 0x10 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x0a }, + { 0x52, 0x00 }, { 0x53, 0x02 }, { 0x54, 0x04 }, { 0x55, 0x06 }, + { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, + { 0x5a, 0x1a }, { 0x5b, 0x00 }, { 0x5c, 0xc0 }, + { 0x61, 0x20 }, + { 0x70, 0x06 }, { 0x71, 0x08 }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x1e }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x9f }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, @@ -2842,33 +2859,31 @@ void genesys_init_sensor_tables() { 0x98, 0x21 }, }, }, - { { 1200 }, 10528, { 388, 574, 393 }, { 0, 1 }, { - // { 0x16, 0x00 }, // FIXME: check if default value is different + { { 1200 }, 10528, { 6071, 6670, 6042 }, { 0, 1 }, { { 0x16, 0x10 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 },{ 0x20, 0x08 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 },{ 0x20, 0x08 }, { 0x52, 0x00 }, { 0x53, 0x02 }, { 0x54, 0x04 }, { 0x55, 0x06 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x1a }, { 0x5b, 0x00 }, { 0x5c, 0xc0 }, { 0x61, 0x20 }, - // { 0x70, 0x00 }, // FIXME: check if default value is different + { 0x70, 0x06 }, { 0x71, 0x08 }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x1e }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x9f }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, - { 0x88, 0x00 }, { 0x89, 0x65 }, + { 0x88, 0x12 }, { 0x89, 0x47 }, { 0x93, 0x00 }, { 0x94, 0x14 }, { 0x95, 0x30 }, { 0x96, 0x00 }, { 0x97, 0xa3 }, { 0x98, 0x22 }, } }, - { { 2400 }, 20864, { 6839, 8401, 6859 }, { 0, 2, 1, 3 }, { - // { 0x16, 0x00 }, // FIXME: check if default value is different + { { 2400 }, 20864, { 7451, 8661, 7405 }, { 0, 2, 1, 3 }, { { 0x16, 0x10 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x06 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x06 }, { 0x52, 0x00 }, { 0x53, 0x02 }, { 0x54, 0x04 }, { 0x55, 0x06 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x1a }, { 0x5b, 0x00 }, { 0x5c, 0xc0 }, { 0x61, 0x20 }, - // { 0x70, 0x00 }, // FIXME: check if default value is different + { 0x70, 0x06 }, { 0x71, 0x08 }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x1e }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x9f }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, @@ -2918,14 +2933,14 @@ void genesys_init_sensor_tables() }; CustomSensorSettings custom_settings[] = { - { { 75, 100, 150, 300 }, 4608, { 894, 1044, 994 }, std::vector{}, { + { { 75, 100, 150, 300 }, 4608, { 1244, 1294, 1144 }, std::vector{}, { { 0x16, 0x15 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x02 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x02 }, { 0x52, 0x04 }, { 0x53, 0x06 }, { 0x54, 0x00 }, { 0x55, 0x02 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x3a }, { 0x5b, 0x00 }, { 0x5c, 0x00 }, { 0x61, 0x20 }, - // { 0x70, 0x00 }, // FIXME: check if default value is different + { 0x70, 0x00 }, { 0x71, 0x1f }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x0f }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, @@ -2935,14 +2950,14 @@ void genesys_init_sensor_tables() { 0x98, 0x21 }, }, }, - { { 600 }, 5360, { 1644, 1994, 1844 }, std::vector{}, { + { { 600 }, 5360, { 2394, 2444, 2144 }, std::vector{}, { { 0x16, 0x11 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x02 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x02 }, { 0x52, 0x04 }, { 0x53, 0x06 }, { 0x54, 0x00 }, { 0x55, 0x02 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x3a }, { 0x5b, 0x00 }, { 0x5c, 0x00 }, { 0x61, 0x20 }, - { 0x70, 0x1f }, + { 0x70, 0x1f }, { 0x71, 0x1f }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x0f }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, @@ -2952,14 +2967,14 @@ void genesys_init_sensor_tables() { 0x98, 0x21 }, }, }, - { { 1200 }, 10528, { 3194, 3794, 3594 }, std::vector{}, { + { { 1200 }, 10528, { 4694, 4644, 4094 }, std::vector{}, { { 0x16, 0x15 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x02 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x02 }, { 0x52, 0x04 }, { 0x53, 0x06 }, { 0x54, 0x00 }, { 0x55, 0x02 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x3a }, { 0x5b, 0x00 }, { 0x5c, 0x00 }, { 0x61, 0x20 }, - { 0x70, 0x1f }, + { 0x70, 0x1f }, { 0x71, 0x1f }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x0f }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, @@ -2969,14 +2984,14 @@ void genesys_init_sensor_tables() { 0x98, 0x21 }, }, }, - { { 2400 }, 20864, { 6244, 7544, 7094 }, std::vector{}, { + { { 2400 }, 20864, { 8944, 8144, 7994 }, std::vector{}, { { 0x16, 0x11 }, { 0x17, 0x04 }, { 0x18, 0x00 }, { 0x19, 0x01 }, - { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x01 }, { 0x20, 0x02 }, + { 0x1a, 0x30 }, { 0x1b, 0x00 }, { 0x1c, 0x02 }, { 0x1d, 0x00 }, { 0x20, 0x02 }, { 0x52, 0x04 }, { 0x53, 0x06 }, { 0x54, 0x00 }, { 0x55, 0x02 }, { 0x56, 0x04 }, { 0x57, 0x04 }, { 0x58, 0x04 }, { 0x59, 0x04 }, { 0x5a, 0x3a }, { 0x5b, 0x00 }, { 0x5c, 0x00 }, { 0x61, 0x20 }, - // { 0x70, 0x00 }, // FIXME: check if default value is different + { 0x70, 0x00 }, { 0x71, 0x1f }, { 0x72, 0x08 }, { 0x73, 0x0a }, { 0x74, 0x00 }, { 0x75, 0x00 }, { 0x76, 0x0f }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x55 }, diff --git a/backend/gt68xx.c b/backend/gt68xx.c index 3fb8687d1..00190fefd 100644 --- a/backend/gt68xx.c +++ b/backend/gt68xx.c @@ -947,25 +947,30 @@ download_firmware_file (GT68xx_Device * dev) if (strncmp (dev->model->firmware_name, PATH_SEP, 1) != 0) { /* probably filename only */ - snprintf (filename, PATH_MAX, "%s%s%s%s%s%s%s", + snprintf (filename, sizeof(filename), "%s%s%s%s%s%s%s", STRINGIFY (PATH_SANE_DATA_DIR), PATH_SEP, "sane", PATH_SEP, "gt68xx", PATH_SEP, dev->model->firmware_name); - snprintf (dirname, PATH_MAX, "%s%s%s%s%s", + snprintf (dirname, sizeof(dirname), "%s%s%s%s%s", STRINGIFY (PATH_SANE_DATA_DIR), PATH_SEP, "sane", PATH_SEP, "gt68xx"); - strncpy (basename, dev->model->firmware_name, PATH_MAX); + strncpy (basename, dev->model->firmware_name, sizeof(basename) - 1); + basename[sizeof(basename) - 1] = '\0'; } else { /* absolute path */ char *pos; - strncpy (filename, dev->model->firmware_name, PATH_MAX); - strncpy (dirname, dev->model->firmware_name, PATH_MAX); + strncpy (filename, dev->model->firmware_name, sizeof(filename) - 1); + filename[sizeof(filename) - 1] = '\0'; + strncpy (dirname, dev->model->firmware_name, sizeof(dirname) - 1); + dirname[sizeof(dirname) - 1] = '\0'; + pos = strrchr (dirname, PATH_SEP[0]); if (pos) pos[0] = '\0'; - strncpy (basename, pos + 1, PATH_MAX); + strncpy (basename, pos + 1, sizeof(basename) - 1); + basename[sizeof(basename) - 1] = '\0'; } /* first, try to open with exact case */ @@ -994,11 +999,16 @@ download_firmware_file (GT68xx_Device * dev) { direntry = readdir (dir); if (direntry - && (strncasecmp (direntry->d_name, basename, PATH_MAX) == - 0)) + && (strncasecmp (direntry->d_name, basename, PATH_MAX) == 0)) { - snprintf (filename, PATH_MAX, "%s%s%s", - dirname, PATH_SEP, direntry->d_name); + int len = snprintf (filename, sizeof(filename), "%s%s%s", + dirname, PATH_SEP, direntry->d_name); + if ((len < 0) || (len >= (int) sizeof(filename))) + { + DBG (5, "download_firmware: filepath `%s%s%s' too long\n", + dirname, PATH_SEP, direntry->d_name); + status = SANE_STATUS_INVAL; + } break; } } diff --git a/backend/hpsj5s.c b/backend/hpsj5s.c index 786a8d692..77fcc4675 100644 --- a/backend/hpsj5s.c +++ b/backend/hpsj5s.c @@ -961,8 +961,7 @@ GetCalibration () { /*WARNING!!! Deadlock possible! */ bTest = CallFunctionWithRetVal (0xB5); } - while ((((bTest & 0x80) == 1) && ((bTest & 0x3F) <= 2)) || - (((bTest & 0x80) == 0) && ((bTest & 0x3F) >= 5))); + while ((bTest & 0x80) ? (bTest & 0x3F) <= 2 : (bTest & 0x3F) >= 5); CallFunctionWithParameter (0xCD, 0); /*Skip this line for ECP: */ @@ -1150,8 +1149,7 @@ CalibrateScanElements () usleep (1); } while ((timeout < 1000) && - ((((bTest & 0x80) == 1) && ((bTest & 0x3F) <= 2)) || - (((bTest & 0x80) == 0) && ((bTest & 0x3F) >= 5)))); + ((bTest & 0x80) ? (bTest & 0x3F) <= 2 : (bTest & 0x3F) >= 5)); /*Let's read it... */ if(timeout < 1000) @@ -1218,8 +1216,7 @@ CalibrateScanElements () usleep (1); } while ((timeout < 1000) && - ((((bTest & 0x80) == 1) && ((bTest & 0x3F) <= 2)) || - (((bTest & 0x80) == 0) && ((bTest & 0x3F) >= 5)))); + ((bTest & 0x80) ? (bTest & 0x3F) <= 2 : (bTest & 0x3F) >= 5)); /*Let's read it... */ if(timeout < 1000) diff --git a/backend/ibm.c b/backend/ibm.c index e527a0400..1f2622661 100644 --- a/backend/ibm.c +++ b/backend/ibm.c @@ -248,12 +248,14 @@ attach (const char *devnam, Ibm_Device ** devp) dev->sane.name = strdup (devnam); dev->sane.vendor = "IBM"; - str = malloc (sizeof(ibuf.product) + sizeof(ibuf.revision) + 1); + + size_t prod_rev_size = sizeof(ibuf.product) + sizeof(ibuf.revision) + 1; + str = malloc (prod_rev_size); if (str) { - str[0] = '\0'; - strncat (str, (char *)ibuf.product, sizeof(ibuf.product)); - strncat (str, (char *)ibuf.revision, sizeof(ibuf.revision)); + snprintf (str, prod_rev_size, "%.*s%.*s", + (int) sizeof(ibuf.product), (const char *) ibuf.product, + (int) sizeof(ibuf.revision), (const char *) ibuf.revision); } dev->sane.model = str; dev->sane.type = "flatbed scanner"; diff --git a/backend/ricoh.c b/backend/ricoh.c index 58b3a5347..fbe5c58e5 100644 --- a/backend/ricoh.c +++ b/backend/ricoh.c @@ -222,12 +222,14 @@ attach (const char *devnam, Ricoh_Device ** devp) dev->sane.name = strdup (devnam); dev->sane.vendor = "RICOH"; - str = malloc (sizeof(ibuf.product) + sizeof(ibuf.revision) + 1); + + size_t prod_rev_size = sizeof(ibuf.product) + sizeof(ibuf.revision) + 1; + str = malloc (prod_rev_size); if (str) { - str[0] = '\0'; - strncat (str, (char *)ibuf.product, sizeof(ibuf.product)); - strncat (str, (char *)ibuf.revision, sizeof(ibuf.revision)); + snprintf (str, prod_rev_size, "%.*s%.*s", + (int) sizeof(ibuf.product), (const char *) ibuf.product, + (int) sizeof(ibuf.revision), (const char *) ibuf.revision); } dev->sane.model = str; dev->sane.type = "flatbed scanner";