Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • dict.c

    r4c7c21f rf25df21  
    1515#define GROWBY 3 / 2
    1616
    17 void owl_dict_create(owl_dict *d) {
     17int owl_dict_create(owl_dict *d) {
    1818  d->size=0;
    1919  d->els=g_new(owl_dict_el, INITSIZE);
    2020  d->avail=INITSIZE;
     21  if (d->els==NULL) return(-1);
     22  return(0);
    2123}
    2224
     
    5860/* Appends dictionary keys to a list.  Duplicates the keys,
    5961 * so they will need to be freed by the caller. */
    60 void owl_dict_get_keys(const owl_dict *d, owl_list *l) {
     62int owl_dict_get_keys(const owl_dict *d, owl_list *l) {
    6163  int i;
     64  char *dupk;
    6265  for (i=0; i<d->size; i++) {
    63     owl_list_append_element(l, g_strdup(d->els[i].k));
     66    if ((dupk = g_strdup(d->els[i].k)) == NULL) return(-1);
     67    owl_list_append_element(l, dupk);
    6468  }
     69  return(0);
    6570}
    6671
     
    7984{
    8085  int pos, found;
     86  char *dupk;
    8187  found = _owl_dict_find_pos(d, k, &pos);
    8288  if (found && delete_on_replace) {
     
    9399      if (d->els==NULL) return(-1);
    94100    }
     101    if ((dupk = g_strdup(k)) == NULL) return(-1);
    95102    if (pos!=d->size) {
    96103      /* shift forward to leave us a slot */
     
    99106    }
    100107    d->size++;
    101     d->els[pos].k = g_strdup(k);
     108    d->els[pos].k = dupk;
    102109    d->els[pos].v = v;   
    103110    return(0);
Note: See TracChangeset for help on using the changeset viewer.