Hi [2020-03-21 10:05] markus schnalke <mei...@marmaro.de> > [2020-03-19 12:33] Philipp Takacs <phil...@bureaucracy.de> > > I have also removed the > > clear_msg_flags loop from folder_read and folder_realloc. In most cases > > we use calloc, so this isn't necesarry. At one place in folder_realloc > > realloc is used. There I have add a memset. > > > > comment? > > Why were (in the section down below) only the flags outside the > current message range cleared? Now you clear all flags.
Not sure whats make you think this. But if I had to guess I would say it's the "- lo". So a shourt exircourse to the msgstats. msgstats is an array of the lenght ``mp->hghoff - mp->lowoff''. lowoff is the starting offset, so if you want the stats of message 5 you access ``mp->msgstats[5 - mp->mp->lowoff]. hghoff is the end offset so you can change flags for all messagestats in the range lowoff <= i <= hghoff. folder_realloc in this code path increases the hghoff. Now I have to clear all data after the old hghoff. by the way there was a off by one in my path. I fixed it now it looks like this: > > memset(mp->msgstats + mp->hghoff - lo + 1, 0, hi - mp->hghoff); This actually clears less then the code before. The code before started at ``mp->hghmsg + 1''. Now it starts hghoff which is greater or equal to hghmsg. > Does that change the behavior? Yes, like the pathes for seq_read it don't clears flags for msgs which it belive don't exists. But this is actually the reason I created this patch. > Or, if your memset() clears only specific > parts, you probably should put a comment there to explain it, as > this might not be what the programmer usually expects from a > memset() after a (re)alloc(). To me this looks completly like this what I would expect. But I'll think about a good comment. Philipp > Apart from that, your changes look and sound sensible. > > > meillo > > > > From 937c01f62952147a8ff853d8a103dbe8465cb90e Mon Sep 17 00:00:00 2001 > > From: Philipp Takacs <phil...@bureaucracy.de> > > Date: Wed, 18 Mar 2020 21:46:30 +0100 > > Subject: [PATCH 3/3] use memset to clear the msgstats in folder_realloc > > > > --- > > sbr/folder_realloc.c | 16 +--------------- > > 1 file changed, 1 insertion(+), 15 deletions(-) > > > > diff --git a/sbr/folder_realloc.c b/sbr/folder_realloc.c > > index 64a66409..781e8bdc 100644 > > --- a/sbr/folder_realloc.c > > +++ b/sbr/folder_realloc.c > > @@ -46,6 +46,7 @@ folder_realloc(struct msgs *mp, int lo, int hi) > > ** just realloc the message status array. > > */ > > mp->msgstats = mh_xrealloc(mp->msgstats, MSGSTATSIZE(mp, lo, > > hi)); > > + memset(mp->msgstats + mp->hghoff - lo, 0, hi - mp->hghoff); > > } else { > > /* > > ** We are changing the offset of the message status > > @@ -69,20 +70,5 @@ folder_realloc(struct msgs *mp, int lo, int hi) > > mp->lowoff = lo; > > mp->hghoff = hi; > > > > - /* > > - ** Clear all the flags for entries outside > > - ** the current message range for this folder. > > - */ > > - if (mp->nummsg > 0) { > > - for (msgnum = mp->lowoff; msgnum < mp->lowmsg; msgnum++) > > - clear_msg_flags(mp, msgnum); > > - for (msgnum = mp->hghmsg + 1; msgnum <= mp->hghoff; msgnum++) > > - clear_msg_flags(mp, msgnum); > > - } else { > > - /* no messages, so clear entire range */ > > - for (msgnum = mp->lowoff; msgnum <= mp->hghoff; msgnum++) > > - clear_msg_flags(mp, msgnum); > > - } > > - > > return mp; > > } > > -- > > 2.20.1 > > >