[evolution-data-server] Add argument checks to camel-block-file.c.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add argument checks to camel-block-file.c.
- Date: Sat, 22 May 2010 00:06:57 +0000 (UTC)
commit 65e883e781d62aa26b077d9599da0e8a79bc916f
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri May 21 19:58:22 2010 -0400
Add argument checks to camel-block-file.c.
camel/camel-block-file.c | 67 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 56 insertions(+), 11 deletions(-)
---
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index 4bbf928..455975a 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -406,6 +406,9 @@ camel_block_file_rename(CamelBlockFile *bs, const gchar *path)
struct stat st;
gint err;
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), -1);
+ g_return_val_if_fail (path != NULL, -1);
+
CAMEL_BLOCK_FILE_LOCK(bs, io_lock);
ret = g_rename(bs->path, path);
@@ -433,7 +436,8 @@ gint
camel_block_file_delete(CamelBlockFile *bs)
{
gint ret;
- struct _CamelBlockFilePrivate *p = bs->priv;
+
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), -1);
CAMEL_BLOCK_FILE_LOCK(bs, io_lock);
@@ -445,7 +449,7 @@ camel_block_file_delete(CamelBlockFile *bs)
bs->fd = -1;
}
- p->deleted = TRUE;
+ bs->priv->deleted = TRUE;
ret = g_unlink(bs->path);
CAMEL_BLOCK_FILE_UNLOCK(bs, io_lock);
@@ -468,6 +472,8 @@ camel_block_file_new_block (CamelBlockFile *bs)
{
CamelBlock *bl;
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), NULL);
+
CAMEL_BLOCK_FILE_LOCK(bs, root_lock);
if (bs->root->free) {
@@ -505,6 +511,8 @@ camel_block_file_free_block (CamelBlockFile *bs,
{
CamelBlock *bl;
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), -1);
+
bl = camel_block_file_get_block (bs, id);
if (bl == NULL)
return -1;
@@ -538,6 +546,8 @@ camel_block_file_get_block (CamelBlockFile *bs,
{
CamelBlock *bl, *flush, *prev;
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), NULL);
+
/* Sanity check: Dont allow reading of root block (except before its been read)
or blocks with invalid block id's */
if ((bs->root == NULL && id != 0)
@@ -614,8 +624,12 @@ camel_block_file_get_block (CamelBlockFile *bs,
* perform no writes of this block or flushing of it if the cache
* fills.
**/
-void camel_block_file_detach_block(CamelBlockFile *bs, CamelBlock *bl)
+void
+camel_block_file_detach_block(CamelBlockFile *bs, CamelBlock *bl)
{
+ g_return_if_fail (CAMEL_IS_BLOCK_FILE (bs));
+ g_return_if_fail (bl != NULL);
+
CAMEL_BLOCK_FILE_LOCK(bs, cache_lock);
g_hash_table_remove(bs->blocks, GUINT_TO_POINTER(bl->id));
@@ -632,8 +646,12 @@ void camel_block_file_detach_block(CamelBlockFile *bs, CamelBlock *bl)
*
* Reattach a block that has been detached.
**/
-void camel_block_file_attach_block(CamelBlockFile *bs, CamelBlock *bl)
+void
+camel_block_file_attach_block(CamelBlockFile *bs, CamelBlock *bl)
{
+ g_return_if_fail (CAMEL_IS_BLOCK_FILE (bs));
+ g_return_if_fail (bl != NULL);
+
CAMEL_BLOCK_FILE_LOCK(bs, cache_lock);
g_hash_table_insert(bs->blocks, GUINT_TO_POINTER(bl->id), bl);
@@ -651,8 +669,12 @@ void camel_block_file_attach_block(CamelBlockFile *bs, CamelBlock *bl)
* Mark a block as dirty. The block will be written to disk if
* it ever expires from the cache.
**/
-void camel_block_file_touch_block(CamelBlockFile *bs, CamelBlock *bl)
+void
+camel_block_file_touch_block(CamelBlockFile *bs, CamelBlock *bl)
{
+ g_return_if_fail (CAMEL_IS_BLOCK_FILE (bs));
+ g_return_if_fail (bl != NULL);
+
CAMEL_BLOCK_FILE_LOCK(bs, root_lock);
CAMEL_BLOCK_FILE_LOCK(bs, cache_lock);
@@ -680,8 +702,12 @@ void camel_block_file_touch_block(CamelBlockFile *bs, CamelBlock *bl)
* If a block is detatched and this is the last reference, the
* block will be freed.
**/
-void camel_block_file_unref_block(CamelBlockFile *bs, CamelBlock *bl)
+void
+camel_block_file_unref_block(CamelBlockFile *bs, CamelBlock *bl)
{
+ g_return_if_fail (CAMEL_IS_BLOCK_FILE (bs));
+ g_return_if_fail (bl != NULL);
+
CAMEL_BLOCK_FILE_LOCK(bs, cache_lock);
if (bl->refcount == 1 && (bl->flags & CAMEL_BLOCK_DETACHED))
@@ -749,10 +775,14 @@ sync_nolock(CamelBlockFile *bs)
*
* Returns: -1 on io error.
**/
-gint camel_block_file_sync_block(CamelBlockFile *bs, CamelBlock *bl)
+gint
+camel_block_file_sync_block(CamelBlockFile *bs, CamelBlock *bl)
{
gint ret;
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), -1);
+ g_return_val_if_fail (bl != NULL, -1);
+
/* LOCK io_lock */
if (block_file_use(bs) == -1)
return -1;
@@ -772,10 +802,13 @@ gint camel_block_file_sync_block(CamelBlockFile *bs, CamelBlock *bl)
*
* Returns: -1 on io error.
**/
-gint camel_block_file_sync(CamelBlockFile *bs)
+gint
+camel_block_file_sync(CamelBlockFile *bs)
{
gint ret;
+ g_return_val_if_fail (CAMEL_IS_BLOCK_FILE (bs), -1);
+
CAMEL_BLOCK_FILE_LOCK(bs, root_lock);
CAMEL_BLOCK_FILE_LOCK(bs, cache_lock);
@@ -1018,6 +1051,9 @@ camel_key_file_rename(CamelKeyFile *kf, const gchar *path)
struct stat st;
gint err;
+ g_return_val_if_fail (CAMEL_IS_KEY_FILE (kf), -1);
+ g_return_val_if_fail (path != NULL, -1);
+
CAMEL_KEY_FILE_LOCK(kf, lock);
ret = g_rename(kf->path, path);
@@ -1045,7 +1081,8 @@ gint
camel_key_file_delete(CamelKeyFile *kf)
{
gint ret;
- struct _CamelKeyFilePrivate *p = kf->priv;
+
+ g_return_val_if_fail (CAMEL_IS_KEY_FILE (kf), -1);
CAMEL_KEY_FILE_LOCK(kf, lock);
@@ -1057,7 +1094,7 @@ camel_key_file_delete(CamelKeyFile *kf)
kf->fp = NULL;
}
- p->deleted = TRUE;
+ kf->priv->deleted = TRUE;
ret = g_unlink(kf->path);
CAMEL_KEY_FILE_UNLOCK(kf, lock);
@@ -1084,6 +1121,10 @@ camel_key_file_write(CamelKeyFile *kf, camel_block_t *parent, gsize len, camel_k
guint32 size;
gint ret = -1;
+ g_return_val_if_fail (CAMEL_IS_KEY_FILE (kf), -1);
+ g_return_val_if_fail (parent != NULL, -1);
+ g_return_val_if_fail (records != NULL, -1);
+
d(printf("write key %08x len = %d\n", *parent, len));
if (len == 0) {
@@ -1136,10 +1177,14 @@ gint
camel_key_file_read(CamelKeyFile *kf, camel_block_t *start, gsize *len, camel_key_t **records)
{
guint32 size;
- glong pos = *start;
+ glong pos;
camel_block_t next;
gint ret = -1;
+ g_return_val_if_fail (CAMEL_IS_KEY_FILE (kf), -1);
+ g_return_val_if_fail (start != NULL, -1);
+
+ pos = *start;
if (pos == 0)
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]