]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Add and use QUOTA_USER_CONTEXT_REQUIRE
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 23 Jan 2018 08:41:35 +0000 (10:41 +0200)
committerMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Tue, 20 Feb 2018 12:36:45 +0000 (14:36 +0200)
Satisfies static analyzers

src/plugins/quota/quota-plugin.h
src/plugins/quota/quota-storage.c

index 8c85329fcc8a340aa6438ee93dafca06cd74c3c4..927d428c1c3e2784fac724a2e180f1bb08de87dd 100644 (file)
@@ -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;
index 09b428cb0a27816f127b2e4f8280de4e098166a2..97b394697c6de003be33e030464202b476aa1ae4 100644 (file)
@@ -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;
@@ -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;
 
@@ -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);
 
@@ -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);
@@ -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);