Fixed a segfault that would occur in adding a User, as a realloc was used when a malloc should have been.
parent
6e12546e06
commit
b5a9757ae0
4
Makefile
4
Makefile
|
@ -21,6 +21,10 @@ nchat: $(OBJS) $(CON_OBJS)
|
|||
xnchat: $(OBJS) $(X11_OBJS)
|
||||
$(CC) $(OBJS) $(X11_OBJS) $(LFLAGS) $(X11_LFLAGS) -o xnchat
|
||||
|
||||
install: nchat
|
||||
cp -f nchat /usr/local/bin/
|
||||
chmod +x /usr/local/bin/nchat
|
||||
|
||||
all: nchat xnchat
|
||||
|
||||
clean:
|
||||
|
|
13
users.c
13
users.c
|
@ -11,23 +11,16 @@ int checkUser(UserList *user_list, const char nick[], struct in_addr address) {
|
|||
}
|
||||
|
||||
int addUser(UserList *user_list, const char nick[], struct in_addr address) {
|
||||
int nick_length = strlen(nick)+1;
|
||||
user_list->length++;
|
||||
//printf("Adding!\n");
|
||||
user_list->users = realloc(user_list->users, (user_list->length)*sizeof(User));
|
||||
User new_user;
|
||||
new_user.last_address = address;
|
||||
new_user.nick = realloc(new_user.nick, strlen(nick)+1);
|
||||
// new_user.nick = malloc(strlen(nick));
|
||||
new_user.nick = malloc(nick_length);
|
||||
new_user.addresses = malloc(1);
|
||||
new_user.address_count = 0;
|
||||
//strcpy(new_user.nick, nick);
|
||||
//memcpy(new_user.nick, nick, strlen(nick)+1);
|
||||
memcpy(new_user.nick, nick, strlen(nick));
|
||||
// new_user.last_address = malloc(sizeof(struct in_addr));
|
||||
// memcpy(new_user.last_address, &address, sizeof(struct in_addr));
|
||||
//new_user.last_address = malloc(new_user.last_address, sizeof(struct in_addr));
|
||||
memcpy(new_user.nick, nick, nick_length);
|
||||
addUserAddress(&new_user, address);
|
||||
//new_user.last_address = &new_user.addresses[new_user.address_count-1];
|
||||
user_list->users[user_list->length-1] = new_user;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue