[sane-devel] Fix for array subscript error in niash.c

Bertrik Sikken bertrik at sikken.nl
Wed Feb 21 20:46:30 CET 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Johannes Meixner wrote:
> Hello,
> 
> the newest GNU compiler found an array subscript error
> in backend/niash.c of sane-backends-1.0.18, see
> https://bugzilla.novell.com/show_bug.cgi?id=246654
> 
> It happens because the arrays are defined with a size of optLast
> but actually optLast is not the last entry in the enumeration.
> Therefore I added an optEndOfList at the very end:
> --------------------------------------------------------------------
> --- backend/niash.c.orig        2006-02-04 12:34:28.000000000 +0100
> +++ backend/niash.c     2007-02-21 15:38:12.000000000 +0100
> @@ -89,7 +89,9 @@ typedef enum
>    optLamp,
>  
>    optCalibrate,
> -  optGamma                      /* analog gamma = single number */
> +  optGamma,                     /* analog gamma = single number */
> +/* have optEndOfList only to define arrays with sufficient size */
> +  optEndOfList
>  } EOptionIndex;
>  
>  
> @@ -105,8 +107,8 @@ typedef union
>  
>  typedef struct
>  {
> -  SANE_Option_Descriptor aOptions[optLast];
> -  TOptionValue aValues[optLast];
> +  SANE_Option_Descriptor aOptions[optEndOfList];
> +  TOptionValue aValues[optEndOfList];
>  
>    TScanParams ScanParams;
>    THWParams HWParams;
> --------------------------------------------------------------------

(I am the original author of the niash backend but no longer the active
maintainer.)

The optLast option is indeed used to signify the number of available
options. By placing an option behind optLast, it becomes invisible and
inaccessible from the SANE API (at least that's the intention).
This was a convenient hack to quickly enable or disable an experimental
option in the beginning of the development of the backend.

I think that adding an additional optEndOfList only complicates things
more.

How about simply removing the options beyond optLast (such that optLast
is indeed the last option). They are not used in the backend anyway.

Kind regards,
Bertrik

P.S. Nice to see that someone is actually checking sane-backends for
compile warnings :P
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF3KGWETD6mlrWxPURArb0AJ4+JAG8dzFdKxJ6U3lHte99lP4vvwCfTQgo
xKPX9XJ+lRJRTGqSxz3pZIE=
=buu5
-----END PGP SIGNATURE-----



More information about the sane-devel mailing list