Skip to content

Commit

Permalink
quota: Add and use QUOTA_USER_CONTEXT_REQUIRE
Browse files Browse the repository at this point in the history
Satisfies static analyzers
  • Loading branch information
cmouse authored and mrannanj committed Feb 20, 2018
1 parent 019febb commit fe1ec4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/plugins/quota/quota-plugin.h
Expand Up @@ -11,6 +11,8 @@ struct mail;

#define QUOTA_USER_CONTEXT(obj) \
MODULE_CONTEXT(obj, quota_user_module)
#define QUOTA_USER_CONTEXT_REQUIRE(obj) \
MODULE_CONTEXT_REQUIRE(obj, quota_user_module)

struct quota_user {
union mail_user_module_context module_ctx;
Expand Down
14 changes: 5 additions & 9 deletions src/plugins/quota/quota-storage.c
Expand Up @@ -76,7 +76,7 @@ static void quota_mail_expunge(struct mail *_mail)
{
struct mail_private *mail = (struct mail_private *)_mail;
struct quota_mailbox *qbox = QUOTA_CONTEXT_REQUIRE(_mail->box);
struct quota_user *quser = QUOTA_USER_CONTEXT(_mail->box->storage->user);
struct quota_user *quser = QUOTA_USER_CONTEXT_REQUIRE(_mail->box->storage->user);
union mail_module_context *qmail = QUOTA_MAIL_CONTEXT(mail);
struct quota_transaction_context *qt = QUOTA_CONTEXT_REQUIRE(_mail->transaction);
uoff_t size;
Expand Down Expand Up @@ -215,10 +215,9 @@ quota_move_requires_check(struct mailbox *dest_box, struct mailbox *src_box)
{
struct mail_namespace *src_ns = src_box->list->ns;
struct mail_namespace *dest_ns = dest_box->list->ns;
struct quota_user *quser = QUOTA_USER_CONTEXT(src_ns->user);
struct quota_user *quser = QUOTA_USER_CONTEXT_REQUIRE(src_ns->user);
struct quota_root *const *rootp;

i_assert(quser != NULL);
array_foreach(&quser->quota->roots, rootp) {
bool have_src_quota, have_dest_quota;

Expand Down Expand Up @@ -397,13 +396,12 @@ static void quota_mailbox_sync_notify(struct mailbox *box, uint32_t uid,
{
struct quota_mailbox *qbox = QUOTA_CONTEXT_REQUIRE(box);
struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
struct quota_user *quser = QUOTA_USER_CONTEXT(box->storage->user);
struct quota_user *quser = QUOTA_USER_CONTEXT_REQUIRE(box->storage->user);
const uint32_t *uids;
const uoff_t *sizep;
unsigned int i, count;
uoff_t size;

i_assert(quser != NULL);
if (qbox->module_ctx.super.sync_notify != NULL)
qbox->module_ctx.super.sync_notify(box, uid, sync_type);

Expand Down Expand Up @@ -528,9 +526,8 @@ static void quota_roots_flush(struct quota *quota)
static void quota_mailbox_close(struct mailbox *box)
{
struct quota_mailbox *qbox = QUOTA_CONTEXT_REQUIRE(box);
struct quota_user *quser = QUOTA_USER_CONTEXT(box->storage->user);
struct quota_user *quser = QUOTA_USER_CONTEXT_REQUIRE(box->storage->user);

i_assert(quser != NULL);
/* sync_notify() may be called outside sync_begin()..sync_deinit().
make sure we apply changes at close time at latest. */
quota_mailbox_sync_commit(qbox);
Expand Down Expand Up @@ -606,8 +603,7 @@ struct quota *quota_get_mail_user_quota(struct mail_user *user)

static void quota_user_deinit(struct mail_user *user)
{
struct quota_user *quser = QUOTA_USER_CONTEXT(user);
i_assert(quser != NULL);
struct quota_user *quser = QUOTA_USER_CONTEXT_REQUIRE(user);
struct quota_settings *quota_set = quser->quota->set;

quota_deinit(&quser->quota);
Expand Down

0 comments on commit fe1ec4b

Please sign in to comment.