aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-11-30 19:50:11 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-11-30 19:50:11 +0800
commit3fa03e87ea186055823f2942db04317b79b90efe (patch)
tree695ef9a026c817ac57a21a7a3b84e6928f533249
parent9b49b3e25a171e87b556fe33d4f9f5fbf1bdae53 (diff)
downloadgsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.tar
gsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.tar.gz
gsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.tar.bz2
gsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.tar.lz
gsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.tar.xz
gsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.tar.zst
gsoc2013-evolution-3fa03e87ea186055823f2942db04317b79b90efe.zip
Fix typename of args (for all funcs). (e_strv_set_ref): Assert the index
2000-11-30 Not Zed <NotZed@HelixCode.com> * e-memory.c (e_strv_new): Fix typename of args (for all funcs). (e_strv_set_ref): Assert the index is in range. (e_strv_set_ref_free): " (e_strv_set): " (e_strv_get): " svn path=/trunk/; revision=6733
-rw-r--r--e-util/ChangeLog8
-rw-r--r--e-util/e-memory.c48
-rw-r--r--e-util/e-memory.h2
3 files changed, 37 insertions, 21 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index b45ffddc82..dba0d7a301 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,11 @@
+2000-11-30 Not Zed <NotZed@HelixCode.com>
+
+ * e-memory.c (e_strv_new): Fix typename of args (for all funcs).
+ (e_strv_set_ref): Assert the index is in range.
+ (e_strv_set_ref_free): "
+ (e_strv_set): "
+ (e_strv_get): "
+
2000-11-29 Not Zed <NotZed@HelixCode.com>
* e-sexp.c (term_eval_lt): Plug a memleak, need to free results
diff --git a/e-util/e-memory.c b/e-util/e-memory.c
index 1c3958b6f3..21195edbb1 100644
--- a/e-util/e-memory.c
+++ b/e-util/e-memory.c
@@ -508,7 +508,7 @@ void e_mempool_destroy(MemPool *pool)
#define STRV_UNPACKED ((unsigned char)(~0))
-struct _e_strv {
+struct _EStrv {
unsigned char length; /* how many entries we have (or the token STRV_UNPACKED) */
char data[1]; /* data follows */
};
@@ -521,7 +521,7 @@ struct _s_strv_string {
struct _e_strvunpacked {
unsigned char type; /* we overload last to indicate this is unpacked */
MemPool *pool; /* pool of memory for strings */
- struct _e_strv *source; /* if we were converted from a packed one, keep the source around for a while */
+ struct _EStrv *source; /* if we were converted from a packed one, keep the source around for a while */
unsigned int length;
struct _s_strv_string strings[1]; /* the string array data follows */
};
@@ -543,7 +543,7 @@ struct _e_strvunpacked {
*
* Return value:
**/
-struct _e_strv *
+struct _EStrv *
e_strv_new(int size)
{
struct _e_strvunpacked *s;
@@ -558,11 +558,11 @@ e_strv_new(int size)
s->source = NULL;
memset(s->strings, 0, size*sizeof(s->strings[0]));
- return (struct _e_strv *)s;
+ return (struct _EStrv *)s;
}
static struct _e_strvunpacked *
-strv_unpack(struct _e_strv *strv)
+strv_unpack(struct _EStrv *strv)
{
struct _e_strvunpacked *s;
register char *p;
@@ -601,8 +601,8 @@ strv_unpack(struct _e_strv *strv)
* Return value: A new EStrv if the strv has already
* been packed, otherwise @strv.
**/
-struct _e_strv *
-e_strv_set_ref(struct _e_strv *strv, int index, char *str)
+struct _EStrv *
+e_strv_set_ref(struct _EStrv *strv, int index, char *str)
{
struct _e_strvunpacked *s;
@@ -613,9 +613,11 @@ e_strv_set_ref(struct _e_strv *strv, int index, char *str)
else
s = (struct _e_strvunpacked *)strv;
+ g_assert(index>=0 && index < s->length);
+
s->strings[index].string = str;
- return (struct _e_strv *)s;
+ return (struct _EStrv *)s;
}
/**
@@ -632,8 +634,8 @@ e_strv_set_ref(struct _e_strv *strv, int index, char *str)
* Return value: @strv if already unpacked, otherwise an packed
* EStrv.
**/
-struct _e_strv *
-e_strv_set_ref_free(struct _e_strv *strv, int index, char *str)
+struct _EStrv *
+e_strv_set_ref_free(struct _EStrv *strv, int index, char *str)
{
struct _e_strvunpacked *s;
@@ -644,12 +646,14 @@ e_strv_set_ref_free(struct _e_strv *strv, int index, char *str)
else
s = (struct _e_strvunpacked *)strv;
+ g_assert(index>=0 && index < s->length);
+
s->strings[index].string = str;
if (s->strings[index].free)
g_free(s->strings[index].free);
s->strings[index].free = str;
- return (struct _e_strv *)s;
+ return (struct _EStrv *)s;
}
/**
@@ -667,8 +671,8 @@ e_strv_set_ref_free(struct _e_strv *strv, int index, char *str)
* Return value: A new EStrv if the strv has already
* been packed, otherwise @strv.
**/
-struct _e_strv *
-e_strv_set(struct _e_strv *strv, int index, const char *str)
+struct _EStrv *
+e_strv_set(struct _EStrv *strv, int index, const char *str)
{
struct _e_strvunpacked *s;
@@ -679,13 +683,15 @@ e_strv_set(struct _e_strv *strv, int index, const char *str)
else
s = (struct _e_strvunpacked *)strv;
+ g_assert(index>=0 && index < s->length);
+
if (s->pool == NULL)
s->pool = e_mempool_new(1024, 512, E_MEMPOOL_ALIGN_BYTE);
s->strings[index].string = e_mempool_alloc(s->pool, strlen(str)+1);
strcpy(s->strings[index].string, str);
- return (struct _e_strv *)s;
+ return (struct _EStrv *)s;
}
/**
@@ -699,8 +705,8 @@ e_strv_set(struct _e_strv *strv, int index, const char *str)
*
* Return value:
**/
-struct _e_strv *
-e_strv_pack(struct _e_strv *strv)
+struct _EStrv *
+e_strv_pack(struct _EStrv *strv)
{
struct _e_strvunpacked *s;
int len, i;
@@ -727,7 +733,7 @@ e_strv_pack(struct _e_strv *strv)
*dst++ = 0;
}
}
- e_strv_destroy((struct _e_strv *)s);
+ e_strv_destroy((struct _EStrv *)s);
}
return strv;
}
@@ -744,12 +750,13 @@ e_strv_pack(struct _e_strv *strv)
* Return value:
**/
char *
-e_strv_get(struct _e_strv *strv, int index)
+e_strv_get(struct _EStrv *strv, int index)
{
struct _e_strvunpacked *s;
char *p;
if (strv->length != STRV_UNPACKED) {
+ g_assert(index>=0 && index < strv->length);
p = strv->data;
while (index > 0) {
while (*p++ != 0)
@@ -759,6 +766,7 @@ e_strv_get(struct _e_strv *strv, int index)
return p;
} else {
s = (struct _e_strvunpacked *)strv;
+ g_assert(index>=0 && index < s->length);
return s->strings[index].string?s->strings[index].string:"";
}
}
@@ -771,7 +779,7 @@ e_strv_get(struct _e_strv *strv, int index)
* or unpacked strv's.
**/
void
-e_strv_destroy(struct _e_strv *strv)
+e_strv_destroy(struct _EStrv *strv)
{
struct _e_strvunpacked *s;
int i;
@@ -808,7 +816,7 @@ main()
MemChunk *mc;
void *mem, *last;
GMemChunk *gmc;
- struct _e_strv *s;
+ struct _EStrv *s;
s = strv_new(8);
s = strv_set(s, 1, "Testing 1");
diff --git a/e-util/e-memory.h b/e-util/e-memory.h
index ce3a3b9dd1..911bb36b7a 100644
--- a/e-util/e-memory.h
+++ b/e-util/e-memory.h
@@ -52,7 +52,7 @@ void e_mempool_destroy(EMemPool *pool);
/* strv's string arrays that can be efficiently modified and then compressed mainly for retrival */
/* building is relatively fast, once compressed it takes the minimum amount of memory possible to store */
-typedef struct _e_strv EStrv;
+typedef struct _EStrv EStrv;
EStrv *e_strv_new(int size);
EStrv *e_strv_set_ref(EStrv *strv, int index, char *str);