From 4702ee6467ec406ab58d3a5cb4e3144133ba4909 Mon Sep 17 00:00:00 2001 From: bg Date: Tue, 18 Sep 2012 17:18:55 +0200 Subject: [PATCH] clearification of keysize descriptor stuff --- bcal/keysize_descriptor.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/bcal/keysize_descriptor.c b/bcal/keysize_descriptor.c index 579ef56..20f5caf 100644 --- a/bcal/keysize_descriptor.c +++ b/bcal/keysize_descriptor.c @@ -28,50 +28,49 @@ #include #include "keysize_descriptor.h" +#define KS8 ((uint8_t*)ks_desc) uint8_t is_valid_keysize_P(const void* ks_desc, uint16_t keysize){ uint8_t type; - type = *((uint8_t*)ks_desc); - ks_desc = (uint8_t*)ks_desc + 1; + type = KS8[0]; + ks_desc = KS8 + 1; if(type==KS_TYPE_TERMINATOR) return 0; if(type==KS_TYPE_LIST){ uint8_t items; uint16_t item; - items = *((uint8_t*)ks_desc); - ks_desc = (uint8_t*)ks_desc + 1; + items = KS8[0]; + ks_desc = KS8 + 1; while(items--){ - item = *((uint16_t*)ks_desc); - ks_desc = (uint8_t*)ks_desc + 2; + item = KS8[1] * 256 + KS8[0]; + ks_desc = KS8 + 2; if(item==keysize) return 1; } - ks_desc = (uint8_t*)ks_desc - 2; + ks_desc = KS8 - 2; } if(type==KS_TYPE_RANGE){ uint16_t max, min; - min = *((uint16_t*)ks_desc); + min = KS8[1] * 256 + KS8[0]; ks_desc = (uint8_t*)ks_desc + 2; - max = *((uint16_t*)ks_desc); - if(min<=keysize && keysize<=max) + max = KS8[1] * 256 + KS8[0]; + if(min <= keysize && keysize <= max) return 1; } if(type==KS_TYPE_ARG_RANGE){ uint16_t max, min, dist, offset; - min = *((uint16_t*)ks_desc); - ks_desc = (uint8_t*)ks_desc + 2; - max = *((uint16_t*)ks_desc); - ks_desc = (uint8_t*)ks_desc + 2; - dist = *((uint16_t*)ks_desc); - ks_desc = (uint8_t*)ks_desc + 2; - offset = *((uint16_t*)ks_desc); - if(min<=keysize && keysize<=max && (keysize%dist==offset)) + min = KS8[1] * 256 + KS8[0]; + max = KS8[3] * 256 + KS8[2]; + dist = KS8[5] * 256 + KS8[4]; + offset = KS8[7] * 256 + KS8[6]; + ks_desc = KS8 + 6; + if(min <= keysize && keysize <= max && (keysize % dist == offset)) return 1; } if(type>KS_TYPE_ARG_RANGE){ /* bad error, you may insert a big warning message here */ return 0; } - return is_valid_keysize_P((uint8_t*)ks_desc+1, keysize); /* search the next record */ + return is_valid_keysize_P(KS8+1, keysize); /* search the next record */ } uint16_t get_keysize(const void* ks_desc){ -- 2.39.5