Welcome to the Builder Academy

Question Bug in Get_number

More
11 Feb 2014 00:26 - 11 Feb 2014 00:27 #4690 by cunning
Bug in Get_number was created by cunning
Hi,
after hours of debugging, I finally found an answer bug that was bugging me.(pun intended.

In handler.c
get_number is called for find_target_room. The issue here is if you use goto 9.king for example. It would corrupt the string, and all I would get is target not found.

After some serious debugging, I found that num would be 9, but the mobobjstr would return kngn.

I tried this on at, and anything that required get_number.

It did not affect anything such as 10.king or jupiter, 2.jupiter because the strings were longer.


Now honestly I always worry a little on a strcpy. After many debug statements I finally tracked down the bug to this little ole line...

strcpy(*name, ppos);

I replaced it with: *name = strdup(ppos);

Wallah! now you can do any type of x.king, and I validated it against all things that used find_target_room.


I am not sure some would consider this a bug, but when your immortals cannot goto a specific king when there are 30 of them, it bugs people. Then I heard about "at", and so on.


Just wanted to let others know this.

Cunning
Last edit: 11 Feb 2014 00:27 by cunning.
The following user(s) said Thank You: Fizban

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

More
15 Feb 2014 15:14 #4699 by drefs
Replied by drefs on topic Bug in Get_number
im not remember but this modified fix this.
Code:
int isname(const char *str, const char *namelist) { char *newlist; char *curtok; if (!str || !*str || !namelist || !*namelist) return 0; if (!strcmp(str, namelist)) /* the easy way */ return 1; newlist = strdup(namelist); /* make a copy since strtok 'modifies' strings */ for(curtok = strtok(newlist, WHITESPACE); curtok; curtok = strtok(NULL, WHITESPACE)) if(curtok && is_abbrev(str, curtok)) { /* Don't allow abbreviated numbers. - Sryth */ if (isdigit(*str) && (atoi(str) != atoi(curtok))) - return 0; + continue; free(newlist); return 1; } free(newlist); return 0; } my get_number 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, '.')) != NULL) { *ppos++ = '\0'; strlcpy(number, *name, sizeof(number)); strcpy(*name, ppos); for (i = 0; *(number + i); i++) if (!isdigit(*(number + i))) return (0); return (atoi(number)); } return (1); }

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

More
17 Feb 2014 15:33 #4701 by cunning
Replied by cunning on topic Bug in Get_number
That did not fix the issue. I put my fix back in and it worked again.

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

Time to create page: 0.173 seconds