[sane-devel] hs2p backend
jazz_johnson at verizon.net
jazz_johnson at verizon.net
Wed Nov 21 05:18:19 UTC 2007
On Tuesday 20 November 2007, m. allan noah wrote:
> my flags from backend/Makefile (generated by stock configure)
>
> CFLAGS = -g -O2 -W -Wall -Wcast-align -Wcast-qual
> -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith
> -Wreturn-type -Wstrict-prototypes -pedantic -ansi
>
> not sure why yours are not the same?
I finally figured out that I needed to specifiy --enable-warnings for configure:
if test "${ac_cv_c_compiler_gnu}" = "yes"; then
NORMAL_CFLAGS="\
-W \
-Wall"
WARN_CFLAGS="\
-W \
-Wall \
-Wcast-align \
-Wcast-qual \
-Wmissing-declarations \
-Wmissing-prototypes \
-Wpointer-arith \
-Wreturn-type \
-Wstrict-prototypes \
-pedantic"
So I re-configured:
sane-backends# autoheader;autoconf;./configure --enable-warnings
and finally got gcc to run with warnings!
With warnings enabled I was finally able to eliminate all the warnings except
the two free(sane.name) and free(sane.model) in sane_exit();
Finally figured out that I can cast something to const but not the reverse, ie.
char *s;
(const char *)s; /* this is OK */
const char *s;
(char *)s; /* this cast discards qualifiers from pointer target type */
>
> ok, current code recompiled on older 64 bit gcc, with above CFLAGS, my
> comments in []:
>
> In file included from hs2p.c:95:
> hs2p-scsi.c: In function 'print_bytes':
> hs2p-scsi.c:70: warning: cast discards qualifiers from pointer target type
>
> [use const in your casts, since the arg is const void *]
>
> hs2p.c: In function 'sane_hs2p_exit':
> hs2p.c:1394: warning: cast discards qualifiers from pointer target type
> hs2p.c:1395: warning: cast discards qualifiers from pointer target type
>
> [this one i am not sure, cause we are trying to free a const string?]
I tried every type of cast I could think of, but I can't remove this warning.
I fixed the following warnings by changing
get_list_index( char **, char *)
to
get_list_index( const char **, char *)
and then making the opposite casts in my macro function calls:
# grep get_list_index hs2p*.h
hs2p.h:#define get_paddingtype_id(s) (get_list_index( paddingtype_list, (char *)(s) ))
hs2p.h:#define get_halftone_code_id(s) (get_list_index( halftone_code, (char *)(s) ))
hs2p.h:#define get_halftone_pattern_id(s) (get_list_index( halftone_pattern_list, (char *)(s) ))
hs2p.h:#define get_auto_binarization_id(s) (get_list_index( auto_binarization_list, (char *)(s) ))
hs2p.h:#define get_auto_separation_id(s) (get_list_index( auto_separation_list, (char *)(s) ))
hs2p.h:#define get_noisematrix_id(s) (get_list_index( noisematrix_list, (char *)(s) ))
hs2p.h:#define get_grayfilter_id(s) (get_list_index( grayfilter_list, (char *)(s) ))
hs2p.h:#define get_paper_id(s) (get_list_index( paper_list, (char *)(s) ))
hs2p.h:#define get_compression_id(s) (get_list_index( (const char **)compression_list, (char *)(s) ))
hs2p.h:#define get_scan_source_id(s) (get_list_index( (const char **)scan_source_list, (char *)(s) ))
>
> hs2p.c: In function 'sane_hs2p_control_option':
> hs2p.c:1869: warning: cast discards qualifiers from pointer target type
>
> [paper_list is declared a SANE_String_Const array, but its cast to (char
> **)]
>
> hs2p.c: In function 'set_window_data':
> hs2p.c:2140: warning: cast discards qualifiers from pointer target type
> hs2p.c:2144: warning: cast discards qualifiers from pointer target type
> hs2p.c:2165: warning: cast discards qualifiers from pointer target type
> hs2p.c:2195: warning: cast discards qualifiers from pointer target type
> hs2p.c:2203: warning: cast discards qualifiers from pointer target type
> hs2p.c:2216: warning: cast discards qualifiers from pointer target type
> hs2p.c:2219: warning: cast discards qualifiers from pointer target type
> hs2p.c: In function 'sane_hs2p_start':
> hs2p.c:2326: warning: cast discards qualifiers from pointer target type
>
> [same as above?]
>
> again, this not at all required, and we've got the ansi C ones taken
> care of, so dont worry too much.
>
> allan
> --
> "The truth is an offense, but not a sin"
I've placed latest hs2p_patch.gz on my hs2p_sane_backend website.
It compiles on both x86 and x86_64 with the aforementioned warnings
related to free(sane.name) and free(sane.model) in sane_exit():
# zgrep warn x86_*.gz
x86_64_log.gz:hs2p.c:1394: warning: cast discards qualifiers from pointer target type
x86_64_log.gz:hs2p.c:1395: warning: cast discards qualifiers from pointer target type
x86_log.gz:hs2p.c:1394: warning: cast discards qualifiers from pointer target type
x86_log.gz:hs2p.c:1395: warning: cast discards qualifiers from pointer target type
More information about the sane-devel
mailing list