[evolution-data-server/gnome-2-30] 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/gnome-2-30] Add argument checks to camel-block-file.c.
- Date: Sat, 22 May 2010 00:14:22 +0000 (UTC)
commit 601993c718c67a6db099f47146a955a08bc9653c
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 | 69 ++++++++++++++++++++++++++++++++++++++--------
1 files changed, 57 insertions(+), 12 deletions(-)
---
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index c64d1e4..55ec106 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -411,6 +411,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);
@@ -438,7 +441,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);
@@ -450,7 +454,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);
@@ -472,6 +476,8 @@ CamelBlock *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) {
@@ -507,7 +513,9 @@ gint camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id)
{
CamelBlock *bl;
- bl = camel_block_file_get_block(bs, id);
+ 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 @@ CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id)
{
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 @@ CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id)
* 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);
@@ -1026,6 +1059,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);
@@ -1053,7 +1089,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);
@@ -1065,7 +1102,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);
@@ -1092,6 +1129,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) {
@@ -1144,10 +1185,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]