mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-09 15:23:50 -05:00
Introduced wrapper macros snew(), snewn() and sresize() for the
malloc functions, which automatically cast to the same type they're allocating the size of. Should prevent any future errors involving mallocing the size of the wrong structure type, and will also make life easier if we ever need to turn the PuTTY core code from real C into C++-friendly C. I haven't touched the Mac frontend in this checkin because I couldn't compile or test it. [originally from svn r3014]
This commit is contained in:
19
tree234.c
19
tree234.c
@ -29,13 +29,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "puttymem.h"
|
||||
#include "tree234.h"
|
||||
|
||||
#define smalloc malloc
|
||||
#define sfree free
|
||||
|
||||
#define mknew(typ) ( (typ *) smalloc (sizeof (typ)) )
|
||||
|
||||
#ifdef TEST
|
||||
#define LOG(x) (printf x)
|
||||
#else
|
||||
@ -61,7 +57,7 @@ struct node234_Tag {
|
||||
*/
|
||||
tree234 *newtree234(cmpfn234 cmp)
|
||||
{
|
||||
tree234 *ret = mknew(tree234);
|
||||
tree234 *ret = snew(tree234);
|
||||
LOG(("created tree %p\n", ret));
|
||||
ret->root = NULL;
|
||||
ret->cmp = cmp;
|
||||
@ -128,7 +124,7 @@ static void *add234_internal(tree234 * t, void *e, int index)
|
||||
|
||||
LOG(("adding node %p to tree %p\n", e, t));
|
||||
if (t->root == NULL) {
|
||||
t->root = mknew(node234);
|
||||
t->root = snew(node234);
|
||||
t->root->elems[1] = t->root->elems[2] = NULL;
|
||||
t->root->kids[0] = t->root->kids[1] = NULL;
|
||||
t->root->kids[2] = t->root->kids[3] = NULL;
|
||||
@ -300,7 +296,7 @@ static void *add234_internal(tree234 * t, void *e, int index)
|
||||
LOG((" done\n"));
|
||||
break;
|
||||
} else {
|
||||
node234 *m = mknew(node234);
|
||||
node234 *m = snew(node234);
|
||||
m->parent = n->parent;
|
||||
LOG((" splitting a 4-node; created new node %p\n", m));
|
||||
/*
|
||||
@ -423,7 +419,7 @@ static void *add234_internal(tree234 * t, void *e, int index)
|
||||
}
|
||||
} else {
|
||||
LOG((" root is overloaded, split into two\n"));
|
||||
t->root = mknew(node234);
|
||||
t->root = snew(node234);
|
||||
t->root->kids[0] = left;
|
||||
t->root->counts[0] = lcount;
|
||||
t->root->elems[0] = e;
|
||||
@ -1012,8 +1008,6 @@ void *del234(tree234 * t, void *e)
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define srealloc realloc
|
||||
|
||||
/*
|
||||
* Error reporting function.
|
||||
*/
|
||||
@ -1201,8 +1195,7 @@ void internal_addtest(void *elem, int index, void *realret)
|
||||
|
||||
if (arraysize < arraylen + 1) {
|
||||
arraysize = arraylen + 1 + 256;
|
||||
array = (array == NULL ? smalloc(arraysize * sizeof(*array)) :
|
||||
srealloc(array, arraysize * sizeof(*array)));
|
||||
array = sresize(array, arraysize, void *);
|
||||
}
|
||||
|
||||
i = index;
|
||||
|
Reference in New Issue
Block a user