Rev 4192 | Rev 4243 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4192 | Rev 4197 | ||
---|---|---|---|
Line 69... | Line 69... | ||
69 | int name##_add( name##_ref field, type * value ){ \ |
69 | int name##_add( name##_ref field, type * value ){ \ |
70 | if( name##_is_valid( field )){ \ |
70 | if( name##_is_valid( field )){ \ |
71 | if( field->next == ( field->size - 1 )){ \ |
71 | if( field->next == ( field->size - 1 )){ \ |
72 | type ** tmp; \ |
72 | type ** tmp; \ |
73 | \ |
73 | \ |
74 | tmp = ( type ** ) malloc( sizeof( type * ) * 2 * field->size ); \ |
74 | tmp = ( type ** ) realloc( field->items, sizeof( type * ) * 2 * field->size ); \ |
75 | if( ! tmp ) return ENOMEM; \ |
75 | if( ! tmp ) return ENOMEM; \ |
76 | field->size *= 2; \ |
76 | field->size *= 2; \ |
77 | memcpy( tmp, field->items, sizeof( type * ) * field->next ); \ |
- | |
78 | free( field->items ); \ |
- | |
79 | field->items = tmp; \ |
77 | field->items = tmp; \ |
80 | } \ |
78 | } \ |
81 | field->items[ field->next ] = value; \ |
79 | field->items[ field->next ] = value; \ |
82 | ++ field->next; \ |
80 | ++ field->next; \ |
83 | field->items[ field->next ] = NULL; \ |
81 | field->items[ field->next ] = NULL; \ |