On Sun, Jul 28, 2013 at 06:13:05PM +0200, walter harms wrote: > > > Am 28.07.2013 15:50, schrieb Thomas Klausner: > > On Sat, Jul 27, 2013 at 11:27:59AM +0200, walter harms wrote: > >>> +#define WS_XT_MAP_SIZE (sizeof(wsXtMap)/sizeof(unsigned char)) > >>> + > >> > >> I would be careful here, the type is CARD8, that may be or not > >> size of unsigned char. I prefer using *wsXtMap or wsXtMap[0] > >> that circumvents the problem very nicely. > > > > I just followed the other examples in the file: > > #define WS_USB_MAP_SIZE (sizeof(wsUsbMap)/sizeof(unsigned char)) > > #define WS_XT_MAP_SIZE (sizeof(wsXtMap)/sizeof(unsigned char)) > > #define WS_ADB_MAP_SIZE (sizeof(wsAdbMap)/sizeof(unsigned char)) > > #define WS_LK201_MAP_SIZE (sizeof(wsLk201Map)/sizeof(unsigned char)) > > #define WS_SUN_MAP_SIZE (sizeof(wsSunMap)/sizeof(unsigned char)) > > > > I agree your suggestion is more stable, if something changes. > > > > Should I change them all to use sizeof(*wsFOOMap) instead? > > Thomas > > I am not the maintainer, i simply review patches. > so i suggest: > 1. Go for sizeof(*wsXtMap) in your patch first.
Ok, new patch for that attached. > 2. check if there is a macro like ARRAY_SIZE(x) (sizeof(x)/sizeof(*x)) (i > have no idea ARRAY_SIZE if from linux kernel) There are lots of places defining such a macro. rendercheck/tests.c:#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) xf86-video-ati/src/radeon.h:#define RADEON_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) xcb/util-image/image/test_swap.c:#define SIZE(a) (sizeof (a) / sizeof (a[0])) xf86-video-geode/src/lx_exa.c:#define ARRAY_SIZE(a) (sizeof((a)) / (sizeof(*(a)))) xf86-video-geode/src/lx_video.c:#define ARRAY_SIZE(a) (sizeof((a)) / (sizeof(*(a)))) xf86-video-intel/src/intel.h:#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) ... I'll leave it as-is for now. Thomas
>From 4f5426f70abf7bb0b3cba0c3e3a711b782cb4e44 Mon Sep 17 00:00:00 2001 From: Thomas Klausner <w...@netbsd.org> Date: Mon, 29 Jul 2013 08:59:00 +0200 Subject: [PATCH:xf86-input-keyboard 22/22] Do not assume type in WS_*_MAP_SIZE macros. Suggested by Walter Harms <wha...@bfs.de>. Signed-off-by: Thomas Klausner <w...@netbsd.org> --- src/bsd_KbdMap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bsd_KbdMap.c b/src/bsd_KbdMap.c index 8016a25..06f5b0e 100644 --- a/src/bsd_KbdMap.c +++ b/src/bsd_KbdMap.c @@ -443,7 +443,7 @@ static CARD8 wsUsbMap[] = { /* 230 */ KEY_AltLang, /* Right Alt, AKA AltGr */ /* 231 */ KEY_LMeta, /* Right Meta XXX */ }; -#define WS_USB_MAP_SIZE (sizeof(wsUsbMap)/sizeof(unsigned char)) +#define WS_USB_MAP_SIZE (sizeof(wsUsbMap)/sizeof(*wsUsbMap)) static TransMapRec wsUsb = { @@ -676,7 +676,7 @@ static CARD8 wsXtMap[] = { /* 220 */ KEY_RMeta, /* 221 */ KEY_Menu, }; -#define WS_XT_MAP_SIZE (sizeof(wsXtMap)/sizeof(unsigned char)) +#define WS_XT_MAP_SIZE (sizeof(wsXtMap)/sizeof(*wsXtMap)) static TransMapRec wsXt = { @@ -816,7 +816,7 @@ static CARD8 wsAdbMap[] = { /* 126 */ KEY_NOTUSED, /* 127 */ KEY_Power }; -#define WS_ADB_MAP_SIZE (sizeof(wsAdbMap)/sizeof(unsigned char)) +#define WS_ADB_MAP_SIZE (sizeof(wsAdbMap)/sizeof(*wsAdbMap)) static TransMapRec wsAdb = { @@ -1080,7 +1080,7 @@ static CARD8 wsLk201Map[] = { /* 250 */ KEY_NOTUSED, /* 251 */ KEY_NOTUSED, }; -#define WS_LK201_MAP_SIZE (sizeof(wsLk201Map)/sizeof(unsigned char)) +#define WS_LK201_MAP_SIZE (sizeof(wsLk201Map)/sizeof(*wsLk201Map)) static TransMapRec wsLk201 = { @@ -1219,7 +1219,7 @@ static CARD8 wsSunMap[] = { /* 0x7e */ KEY_NOTUSED, /* 0x7f */ KEY_NOTUSED }; -#define WS_SUN_MAP_SIZE (sizeof(wsSunMap)/sizeof(unsigned char)) +#define WS_SUN_MAP_SIZE (sizeof(wsSunMap)/sizeof(*wsSunMap)) static TransMapRec wsSun = { -- 1.8.3.3
_______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel