Bug 151488

Summary: micq-0.5.0.4-3:array subscript out of range
Product: [openSUSE] SUSE LINUX 10.0 Reporter: David Binderman <dcb314>
Component: BasesystemAssignee: Stefan Dirsch <sndirsch>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Minor    
Priority: P2 - High    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: SuSE Linux 10.1   
Whiteboard:
Found By: Other Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Fixes for macros

Description David Binderman 2006-02-16 13:42:19 UTC
I just tried to compile package micq-0.5.0.4-3 with the Intel C 
compiler.

It said

contact.c(1240): warning #175: subscript out of range

The source code is

    else if (HAS_CAP (cont->caps, CAP_TRILL_CRYPT | CAP_TRILL_2))

but

#define HAS_CAP(caps,cap) (((caps)[cap / 32]) & (1UL << (cap % 32)))

and CAP_TRILL_CRYPT has the value 18 and the CAP_TRILL_2 has a value of 19.
So making the macro subsitution

    else if (((cont->caps)[ CAP_TRILL_CRYPT | CAP_TRILL_2 / 32]) & (1UL << (CAP_TRILL_CRYPT | CAP_TRILL_2 % 32)))

I just checked the C precedence table. Both / and % are higher than | so the
macro expansion is the same as

    else if (((cont->caps)[ CAP_TRILL_CRYPT | (CAP_TRILL_2 / 32)]) & (1UL << (CAP_TRILL_CRYPT | (CAP_TRILL_2 % 32))))

hence the compiler complaining. Suggest modify the macro definition

#define HAS_CAP(caps,cap) (((caps)[(cap) / 32]) & (1UL << ((cap) % 32)))

Note the extra () around the uses of cap to ensure correct evaluation.
Comment 1 Stefan Dirsch 2006-02-17 09:08:39 UTC
Good catch! Good explanation! I'll fix this. Thanks a lot!
Comment 2 Stefan Dirsch 2006-02-17 09:26:07 UTC
Created attachment 68968 [details]
Fixes for macros
Comment 3 Stefan Dirsch 2006-02-17 09:28:34 UTC
fixed for 10.1 Beta > 4.