Welcome to the Builder Academy

Question handler.c - get_number() call and calls

More
21 May 2017 01:13 - 21 May 2017 01:18 #6756 by cunning
For several months this has been bugging me, and finally It was called out as an issue on my game. I did a test using several of the handler object calls which use:
Code:
if (!number) { number = # num = get_number(&name); }

I took out number = get_number(&t) and put NULL for all the spell calls in do_cast(). I was curious to see if in fact this bit of code actually worked. The reason i say this is because "num" is not referenced at all after this bit of code. If number is being referenced in the following:
Code:
struct obj_data *get_obj_in_list_vis(struct char_data *ch, char *name, int *number, struct obj_data *list) { struct obj_data *i; int num; if (!list || !*name || !name) return NULL; if (!number) { number = # num = get_number(&name); } if (*number == 0) return (NULL); for (i = list; i && *number; i = i->next_content) if (is_name(name, i->name)) if (CAN_SEE_OBJ(ch, i)) if (--(*number) == 0) return (i); return NULL; }

Upon doing this we tried cast 'remove curse' 2.rock and 3.rock and it did not work. I logged and was proven correct, number stays at 1.

Cunning: cast 'remove curse' 2.stone
GET_OBJ_IN_LIST: num = 1
GET_OBJ_IN_LIST: number = 1, num = 1
GET_NUMBER: number = 2
GET_OBJ_IN_LIST: num = 1
GET_OBJ_IN_LIST: number = 1, num = 1

My point is that we do all that work when we send NULL into a function, and we calculate that value for num and we never transfer it to number. We assign the value of num to number before we even calculate get_number() and assign it to num. I think we should update all these calls in handler.c to the following:
Code:
if (!number) { num = get_number(&name); number = # }



Take into account the overlap Thomas and I have discussed a few times in another thread with my change to get_number()
Code:
int get_number(char **name) { int i; char number[MAX_INPUT_LENGTH], *ppos; /* * These lines was added to make possible the dot sign to be used as a magic * char on isname() function. */ if (!isdigit(**name)) return (1); *number = '\0'; if ((ppos = strchr(*name, '.'))) { *ppos++ = '\0'; strlcpy(number, *name, sizeof(number)); memmove(*name, ppos, strlen(ppos) +1); <======== This corrects the string overlap for (i = 0; *(number + i); i++) if (!isdigit(*(number + i))) return (0); return (atoi(number)); } return (1); }
Last edit: 21 May 2017 01:18 by cunning.

Please Log in or Create an account to join the conversation.

Time to create page: 0.214 seconds