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)
|
xnchat: $(OBJS) $(X11_OBJS)
|
||||||
$(CC) $(OBJS) $(X11_OBJS) $(LFLAGS) $(X11_LFLAGS) -o xnchat
|
$(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
|
all: nchat xnchat
|
||||||
|
|
||||||
clean:
|
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 addUser(UserList *user_list, const char nick[], struct in_addr address) {
|
||||||
|
int nick_length = strlen(nick)+1;
|
||||||
user_list->length++;
|
user_list->length++;
|
||||||
//printf("Adding!\n");
|
|
||||||
user_list->users = realloc(user_list->users, (user_list->length)*sizeof(User));
|
user_list->users = realloc(user_list->users, (user_list->length)*sizeof(User));
|
||||||
User new_user;
|
User new_user;
|
||||||
new_user.last_address = address;
|
new_user.last_address = address;
|
||||||
new_user.nick = realloc(new_user.nick, strlen(nick)+1);
|
new_user.nick = malloc(nick_length);
|
||||||
// new_user.nick = malloc(strlen(nick));
|
|
||||||
new_user.addresses = malloc(1);
|
new_user.addresses = malloc(1);
|
||||||
new_user.address_count = 0;
|
new_user.address_count = 0;
|
||||||
//strcpy(new_user.nick, nick);
|
memcpy(new_user.nick, nick, nick_length);
|
||||||
//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));
|
|
||||||
addUserAddress(&new_user, address);
|
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;
|
user_list->users[user_list->length-1] = new_user;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue