From 0347722f5b69de06a867b73ddc23388d082ab219 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Mon, 3 Nov 2014 07:33:54 +0100 Subject: [PATCH] Converted msgstats macros & Co. to functions and added range checks This change is a reaction to bug, fixed in changeset 5b093c3. Although the bug was fixed on a higher level, it would have been detected much earlier if we would have had the range checks that we now have. This patch was prepared by Philipp Takacs . --- h/mh.h | 49 -------------- h/prototypes.h | 32 +++++++++ sbr/Makefile.in | 2 +- sbr/seq_msgstats.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+), 50 deletions(-) create mode 100644 sbr/seq_msgstats.c diff --git a/h/mh.h b/h/mh.h index 1331a14..f3fda88 100644 --- a/h/mh.h +++ b/h/mh.h @@ -154,55 +154,6 @@ struct msgs { */ #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats))) -/* -** macros for message and sequence manipulation -*/ -#define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0) -#define copy_msg_flags(mp,i,j) \ - ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff]) -#define get_msg_flags(mp,ptr,msgnum) (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff]) -#define set_msg_flags(mp,ptr,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr)) - -#define does_exist(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS) -#define unset_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS) -#define set_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS) - -#define is_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED) -#define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED) -#define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED) - -#define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN) -#define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN) -#define set_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN) - - -#define in_sequence(mp,seqnum,msgnum) \ - ((mp)->msgstats[(msgnum) - mp->lowoff] & (1 << (FFATTRSLOT + seqnum))) -#define clear_sequence(mp,seqnum,msgnum) \ - ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum))) -#define add_sequence(mp,seqnum,msgnum) \ - ((mp)->msgstats[(msgnum) - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum))) - -#define is_seq_private(mp,seqnum) \ - ((mp)->attrstats & (1 << (FFATTRSLOT + seqnum))) -#define make_seq_public(mp,seqnum) \ - ((mp)->attrstats &= ~(1 << (FFATTRSLOT + seqnum))) -#define make_seq_private(mp,seqnum) \ - ((mp)->attrstats |= (1 << (FFATTRSLOT + seqnum))) -#define make_all_public(mp) \ - ((mp)->attrstats = 0) - -/* -** macros for folder attributes -*/ -#define clear_folder_flags(mp) ((mp)->msgflags = 0) - -#define is_readonly(mp) ((mp)->msgflags & READONLY) -#define set_readonly(mp) ((mp)->msgflags |= READONLY) - -#define other_files(mp) ((mp)->msgflags & OTHERS) -#define set_other_files(mp) ((mp)->msgflags |= OTHERS) - #define NULLMP ((struct msgs *) 0) /* diff --git a/h/prototypes.h b/h/prototypes.h index 9b76d07..26981f8 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -126,3 +126,35 @@ int what_now(char *, int, char *, char *, int, struct msgs *, char *LocalName(void); /* hostname */ char *getusername(void); char *getfullname(void); + + +/* +** prototypes for message and sequence manipulation +*/ +void clear_msg_flags(struct msgs *, int); +void copy_msg_flags(struct msgs *, int, int); +void get_msg_flags(struct msgs *, seqset_t *, int); +void set_msg_flags(struct msgs *, seqset_t *, int); +seqset_t does_exist(struct msgs *, int); +void unset_exists(struct msgs *, int); +void set_exists(struct msgs *, int); +seqset_t is_selected(struct msgs *, int); +void unset_selected(struct msgs *, int); +void set_selected(struct msgs *, int); +seqset_t is_unseen(struct msgs *, int); +void unset_unseen(struct msgs *, int); +void set_unseen(struct msgs *, int); +seqset_t in_sequence(struct msgs *, int, int); +void clear_sequence(struct msgs *, int, int); +void add_sequence(struct msgs *, int, int); + +int is_seq_private(struct msgs *, int); +void make_seq_public(struct msgs *, int); +void make_seq_private(struct msgs *, int); +void make_all_public(struct msgs *); + +void clear_folder_flags(struct msgs *); +int is_readonly(struct msgs *); +void set_readonly(struct msgs *); +int other_files(struct msgs *); +void set_other_files(struct msgs *); diff --git a/sbr/Makefile.in b/sbr/Makefile.in index dfd6c38..6bda370 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -67,7 +67,7 @@ SRCS = addrsbr.c ambigsw.c brkstring.c \ seq_setprev.c seq_setunseen.c signals.c \ smatch.c snprintb.c strcasecmp.c \ strindex.c trim.c trimcpy.c uprf.c vfgets.c fmt_def.c \ - mf.c utils.c m_mktemp.c + mf.c utils.c m_mktemp.c seq_msgstats.c OBJS = $(SRCS:.c=.o) diff --git a/sbr/seq_msgstats.c b/sbr/seq_msgstats.c new file mode 100644 index 0000000..40b8474 --- /dev/null +++ b/sbr/seq_msgstats.c @@ -0,0 +1,189 @@ +/* +** seq_msgstats -- message and sequence manipulation and folder attributes +** +** (These functions had once been macros in h/mh.h) +*/ + +#include + +static void +assert_msg_range(struct msgs *mp, int msgnum) +{ + if (msgnum < mp->lowoff || msgnum > mp->hghoff) { + adios(NULL, "Bug: message out of bounds"); + } +} + + +void +add_sequence(struct msgs *mp, int seqnum, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum)); +} + +void +clear_msg_flags(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] = 0; +} + +void +clear_sequence(struct msgs *mp, int seqnum, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum)); +} + +void +copy_msg_flags(struct msgs *mp, int dstmsg, int srcmsg) +{ + assert_msg_range(mp, srcmsg); + assert_msg_range(mp, dstmsg); + mp->msgstats[dstmsg - mp->lowoff] = mp->msgstats[srcmsg - mp->lowoff]; +} + +seqset_t +does_exist(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + return mp->msgstats[msgnum - mp->lowoff] & EXISTS; +} + +void +get_msg_flags(struct msgs *mp, seqset_t *dst, int msgnum) +{ + assert_msg_range(mp, msgnum); + *dst = mp->msgstats[msgnum - mp->lowoff]; +} + +seqset_t +in_sequence(struct msgs *mp, int seqnum, int msgnum) +{ + assert_msg_range(mp, msgnum); + return mp->msgstats[msgnum - mp->lowoff] & (1 << (FFATTRSLOT + seqnum)); +} + +seqset_t +is_selected(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + return mp->msgstats[msgnum - mp->lowoff] & SELECTED; +} + +seqset_t +is_unseen(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + return mp->msgstats[msgnum - mp->lowoff] & SELECT_UNSEEN; +} + +void +set_exists(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] |= EXISTS; +} + +void +set_msg_flags(struct msgs *mp, seqset_t *src, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] = *src; +} + +void +set_selected(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] |= SELECTED; +} + +void +set_unseen(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] |= SELECT_UNSEEN; +} + +void +unset_exists(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] &= ~EXISTS; +} + +void +unset_selected(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] &= ~SELECTED; +} + +void +unset_unseen(struct msgs *mp, int msgnum) +{ + assert_msg_range(mp, msgnum); + mp->msgstats[msgnum - mp->lowoff] &= ~SELECT_UNSEEN; +} + + +/* +** private/public sequences +*/ + +int +is_seq_private(struct msgs *mp, int seqnum) +{ + return mp->attrstats & (1 << (FFATTRSLOT + seqnum)); +} + +void +make_seq_public(struct msgs *mp, int seqnum) +{ + mp->attrstats &= ~(1 << (FFATTRSLOT + seqnum)); +} +void +make_seq_private(struct msgs *mp, int seqnum) +{ + mp->attrstats |= (1 << (FFATTRSLOT + seqnum)); +} +void +make_all_public(struct msgs *mp) +{ + mp->attrstats = 0; +} + + +/* +** folder attributes +*/ + +void +clear_folder_flags(struct msgs *mp) +{ + mp->msgflags = 0; +} + +int +is_readonly(struct msgs *mp) +{ + return mp->msgflags & READONLY; +} +void +set_readonly(struct msgs *mp) +{ + mp->msgflags |= READONLY; +} + +int +other_files(struct msgs *mp) +{ + return mp->msgflags & OTHERS; +} +void +set_other_files(struct msgs *mp) +{ + mp->msgflags |= OTHERS; +} -- 1.7.10.4