~ubuntu-branches/ubuntu/saucy/mapserver/saucy-security

« back to all changes in this revision

Viewing changes to maphash.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-12-23 14:02:06 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111223140206-n3h9t2hsa8hyslmu
Tags: 6.0.1-2
Added missed stuff for libmapscript-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: maphash.c 9376 2009-10-05 14:09:14Z aboudreault $
 
2
 * $Id: maphash.c 10772 2010-11-29 18:27:02Z aboudreault $
3
3
 *
4
4
 * Project:  MapServer
5
5
 * Purpose:  Implement hashTableObj class.
32
32
#include "mapserver.h"
33
33
#include "maphash.h"
34
34
 
35
 
MS_CVSID("$Id: maphash.c 9376 2009-10-05 14:09:14Z aboudreault $")
 
35
MS_CVSID("$Id: maphash.c 10772 2010-11-29 18:27:02Z aboudreault $")
36
36
 
37
37
static unsigned hash(const char *key)
38
38
{
49
49
    int i;
50
50
    hashTableObj *table;
51
51
    
52
 
    table = (hashTableObj *) malloc(sizeof(hashTableObj));
53
 
    table->items = (struct hashObj **) malloc(sizeof(struct hashObj *)*MS_HASHSIZE);
 
52
    table = (hashTableObj *) msSmallMalloc(sizeof(hashTableObj));
 
53
    table->items = (struct hashObj **) msSmallMalloc(sizeof(struct hashObj *)*MS_HASHSIZE);
54
54
    
55
55
    for (i=0; i<MS_HASHSIZE; i++)
56
56
        table->items[i] = NULL;
64
64
    int i;
65
65
 
66
66
    table->items = (struct hashObj **) malloc(sizeof(struct hashObj *)*MS_HASHSIZE);
67
 
    if (!table->items) {
68
 
        msSetError(MS_MEMERR, "Failed to allocate memory for items", "initHashTable");
69
 
        return MS_FAILURE;
70
 
    }
 
67
    MS_CHECK_ALLOC(table->items, sizeof(struct hashObj *)*MS_HASHSIZE, MS_FAILURE);
 
68
 
71
69
    for (i=0; i<MS_HASHSIZE; i++)
72
70
        table->items[i] = NULL;
73
71
    table->numitems = 0;
138
136
 
139
137
    if (tp == NULL) { /* not found */
140
138
        tp = (struct hashObj *) malloc(sizeof(*tp));
141
 
        if ((tp == NULL) || (tp->key = strdup(key)) == NULL) {
142
 
            msSetError(MS_HASHERR, "No such hash entry", "msInsertHashTable");
143
 
            return NULL;
144
 
        }
 
139
        MS_CHECK_ALLOC(tp, sizeof(*tp), NULL);
 
140
        tp->key = msStrdup(key);
145
141
        hashval = hash(key);
146
142
        tp->next = table->items[hashval];
147
143
        table->items[hashval] = tp;
150
146
        free(tp->data);
151
147
    }
152
148
 
153
 
    if ((tp->data = strdup(value)) == NULL)
 
149
    if ((tp->data = msStrdup(value)) == NULL)
154
150
        return NULL;
155
151
 
156
152
    return tp;
175
171
176
172
    struct hashObj *tp;
177
173
    struct hashObj *prev_tp=NULL;
178
 
    int success = 0;
 
174
    int status = MS_FAILURE;
179
175
 
180
176
    if (!table || !key) {
181
177
        msSetError(MS_HASHERR, "No hash table", "msRemoveHashTable");
191
187
    prev_tp = NULL;
192
188
    while (tp != NULL) {
193
189
        if (strcasecmp(key, tp->key) == 0) {
 
190
            status = MS_SUCCESS;
194
191
            if (prev_tp) {     
195
192
                prev_tp->next = tp->next;
196
193
                free(tp);
201
198
                free(tp);
202
199
                break;
203
200
            }
204
 
            success =1;
205
201
        }
206
202
        prev_tp = tp;
207
203
        tp = tp->next;
208
204
    }
209
205
 
210
 
    if (success) {
 
206
    if (status == MS_SUCCESS)
211
207
        table->numitems--;
212
 
        return MS_SUCCESS;
213
 
    }
214
208
 
215
 
    return MS_FAILURE;
 
209
    return status;
216
210
}
217
211
      
218
212
const char *msFirstKeyFromHashTable( hashTableObj *table )