Further cleanups and fixes in chelp.c:read_file(). Now properly adds NULLs to
terminate the lists, that the code in get_help_topic() expects to be there - fixes a potential crash in /bhelp. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@123 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
[Changes 1.2c01]
|
[Changes 1.2c01]
|
||||||
|
|
||||||
|
* Cleanup the /BHELP code, fixing a potential crash. (caf)
|
||||||
|
|
||||||
* [1.1s01] Sanity check color codes, fixes a potential crash. (caf)
|
* [1.1s01] Sanity check color codes, fixes a potential crash. (caf)
|
||||||
|
|
||||||
* Add /FSET USERMODE_OTHER to correctly format user mode changes where the
|
* Add /FSET USERMODE_OTHER to correctly format user mode changes where the
|
||||||
|
|||||||
@@ -154,10 +154,9 @@ static int first_time = 1;
|
|||||||
int read_file(FILE *help_file, int helpfunc)
|
int read_file(FILE *help_file, int helpfunc)
|
||||||
{
|
{
|
||||||
char line[BIG_BUFFER_SIZE + 1];
|
char line[BIG_BUFFER_SIZE + 1];
|
||||||
char *topic = NULL;
|
|
||||||
char *subject = NULL;
|
|
||||||
int item_number = 0;
|
int item_number = 0;
|
||||||
int topics = 0;
|
int topic = -1;
|
||||||
|
Chelp **index = new_malloc(sizeof index[0]);
|
||||||
|
|
||||||
while (fgets(line, sizeof line, help_file))
|
while (fgets(line, sizeof line, help_file))
|
||||||
{
|
{
|
||||||
@@ -170,51 +169,41 @@ int read_file(FILE *help_file, int helpfunc)
|
|||||||
|
|
||||||
if (*line != ' ') /* we got a topic copy to topic */
|
if (*line != ' ') /* we got a topic copy to topic */
|
||||||
{
|
{
|
||||||
topics++;
|
|
||||||
item_number = 0;
|
|
||||||
if (!my_strnicmp(line, "-RELATED", 7))
|
if (!my_strnicmp(line, "-RELATED", 7))
|
||||||
{
|
{
|
||||||
if (topic)
|
if (topic > -1)
|
||||||
{
|
{
|
||||||
if (helpfunc)
|
index[topic]->relates = m_strdup(line+8);
|
||||||
script_help[topics-1]->relates = m_strdup(line+8);
|
|
||||||
else
|
|
||||||
help_index[topics-1]->relates = m_strdup(line+8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new_free(&topic); new_free(&subject);
|
topic++;
|
||||||
malloc_strcpy(&topic, line);
|
item_number = 0;
|
||||||
if (helpfunc)
|
RESIZE(index, Chelp *, topic + 2);
|
||||||
{
|
|
||||||
RESIZE(script_help, Chelp, topics+1);
|
index[topic] = new_malloc(sizeof(Chelp));
|
||||||
script_help[topics-1] = new_malloc(sizeof(Chelp));
|
index[topic]->title = m_strdup(line);
|
||||||
script_help[topics-1]->title = m_strdup(line);
|
index[topic]->contents = new_malloc(sizeof(char *));
|
||||||
}
|
index[topic]->contents[0] = NULL;
|
||||||
else
|
index[topic]->relates = NULL;
|
||||||
{
|
|
||||||
RESIZE(help_index, Chelp, topics+1);
|
|
||||||
help_index[topics-1] = new_malloc(sizeof(Chelp));
|
|
||||||
help_index[topics-1]->title = m_strdup(line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (topic && *topic)
|
else if (topic > -1)
|
||||||
{ /* we found the subject material */
|
{ /* we found the subject material */
|
||||||
if (helpfunc)
|
item_number++;
|
||||||
{
|
RESIZE(index[topic]->contents, char *, item_number + 1);
|
||||||
RESIZE(script_help[topics-1]->contents, char **, ++item_number);
|
|
||||||
script_help[topics-1]->contents[item_number-1] = m_strdup(line);
|
index[topic]->contents[item_number-1] = m_strdup(line);
|
||||||
}
|
index[topic]->contents[item_number] = NULL;
|
||||||
else
|
|
||||||
{
|
|
||||||
RESIZE(help_index[topics-1]->contents, char **, ++item_number);
|
|
||||||
help_index[topics-1]->contents[item_number-1] = m_strdup(line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (helpfunc)
|
||||||
|
script_help = index;
|
||||||
|
else
|
||||||
|
help_index = index;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user