From 3b437708433af38d025e23c534a65c11680cb81e Mon Sep 17 00:00:00 2001 From: Peter Kirchgessner Date: Mon, 14 Apr 2003 19:29:37 +0000 Subject: [PATCH] Second try to fix problem with null-pointer in sane_control_option --- backend/hp-option.c | 19 ++++++++++++++++++- backend/hp.c | 23 ----------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/backend/hp-option.c b/backend/hp-option.c index 3a77992a2..3d8559edd 100644 --- a/backend/hp-option.c +++ b/backend/hp-option.c @@ -3910,7 +3910,7 @@ sanei_hp_optset_control (HpOptSet this, HpData data, hp_bool_t immediate) { HpOption opt = hp_optset_getByIndex(this, optnum); - SANE_Int my_info = 0; + SANE_Int my_info = 0, my_val = 0; DBG(3,"sanei_hp_optset_control: %s\n", opt ? opt->descriptor->name : ""); @@ -3922,6 +3922,23 @@ sanei_hp_optset_control (HpOptSet this, HpData data, if (!opt) return SANE_STATUS_INVAL; + /* There are problems with SANE_ACTION_GET_VALUE and valp == 0. */ + /* Check if we really need valp. */ + if ((action == SANE_ACTION_GET_VALUE) && (!valp)) + { + /* Options without a value ? */ + if ( (opt->descriptor->type == SANE_TYPE_BUTTON) + || (opt->descriptor->type == SANE_TYPE_GROUP)) + { + valp = &my_val; /* Just simulate a return value locally. */ + } + else /* Others must return a value. So this is invalid */ + { + DBG(1, "sanei_hp_optset_control: get value, but valp == 0\n"); + return SANE_STATUS_INVAL; + } + } + if (immediate) RETURN_IF_FAIL( hp_option_imm_control(this, opt, data, action, valp, infop, scsi) ); diff --git a/backend/hp.c b/backend/hp.c index da5c1fd27..b3639fccc 100644 --- a/backend/hp.c +++ b/backend/hp.c @@ -883,29 +883,6 @@ sane_control_option (SANE_Handle handle, SANE_Int optnum, DBG(10, "sane_control_option called\n"); - status = SANE_STATUS_GOOD; - switch (action) - { - case SANE_ACTION_GET_VALUE: - case SANE_ACTION_SET_VALUE: - if (!valp) - { - DBG (1,"sane_control_option: valp is NULL\n"); - status = SANE_STATUS_INVAL; - } - break; - - case SANE_ACTION_SET_AUTO: - break; - - default: - DBG (1,"sane_control_option: action unknown\n"); - status = SANE_STATUS_INVAL; - break; - } - - if (status != SANE_STATUS_GOOD) return status; - status = sanei_hp_handle_control(h, optnum, action, valp, info); DBG(10, "sane_control_option will finish with %s\n",