realloc->trealloc

This commit is contained in:
vysheng 2014-01-10 17:08:12 +04:00
parent ccc76dd982
commit a97603031c
3 changed files with 9 additions and 2 deletions

View File

@ -685,7 +685,7 @@ void replay_log_event (void) {
assert (C->user_list[i].user_id != user); assert (C->user_list[i].user_id != user);
} }
C->user_list_size ++; C->user_list_size ++;
C->user_list = realloc (C->user_list, 12 * C->user_list_size); C->user_list = trealloc (C->user_list, 12 * C->user_list_size);
C->user_list[C->user_list_size - 1].user_id = user; C->user_list[C->user_list_size - 1].user_id = user;
C->user_list[C->user_list_size - 1].inviter_id = inviter; C->user_list[C->user_list_size - 1].inviter_id = inviter;
C->user_list[C->user_list_size - 1].date = date; C->user_list[C->user_list_size - 1].date = date;
@ -715,7 +715,7 @@ void replay_log_event (void) {
} }
assert (C->user_list[C->user_list_size - 1].user_id == user); assert (C->user_list[C->user_list_size - 1].user_id == user);
C->user_list_size --; C->user_list_size --;
C->user_list = realloc (C->user_list, 12 * C->user_list_size); C->user_list = trealloc (C->user_list, 12 * C->user_list_size);
C->user_list_version = version; C->user_list_version = version;
} }
break; break;

View File

@ -31,6 +31,12 @@ static void out_of_memory (void) {
assert (0 && "Out of memory"); assert (0 && "Out of memory");
} }
void *trealloc (void *ptr, size_t size) {
void *p = realloc (ptr, size);
ensure_ptr (p);
return p;
}
void *talloc (size_t size) { void *talloc (size_t size) {
void *p = malloc (size); void *p = malloc (size);
ensure_ptr (p); ensure_ptr (p);

View File

@ -21,6 +21,7 @@
#define __TOOLS_H__ #define __TOOLS_H__
void *talloc (size_t size); void *talloc (size_t size);
void *trealloc (void *ptr, size_t size);
void *talloc0 (size_t size); void *talloc0 (size_t size);
char *tstrdup (const char *s); char *tstrdup (const char *s);
void ensure (int r); void ensure (int r);