[mw-devel] MW3 r1132 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Sat Dec 12 14:36:46 GMT 2009


Author: welshbyte
Date: 2009-12-12 14:36:46 +0000 (Sat, 12 Dec 2009)
New Revision: 1132

Modified:
   trunk/src/frl.c
   trunk/src/frl.h
   trunk/src/rooms.c
   trunk/src/rooms.h
   trunk/src/sqlite.c
   trunk/src/sqlite.h
Log:
- Remove unused functions from sqlite.c, frl.c and rooms.c
- Fix a possible NULL pointer dereference in sqlite.c


Modified: trunk/src/frl.c
===================================================================
--- trunk/src/frl.c	2009-12-12 07:07:56 UTC (rev 1131)
+++ trunk/src/frl.c	2009-12-12 14:36:46 UTC (rev 1132)
@@ -56,54 +56,6 @@
 }
 
 /**************************************************************
-** Description: repeatedly calls frl from a file until the   **
-**              first lineno starting in the given comment   **
-**          In: FILE* to read from - must be open for read   **
-**              char* comment to ignore - if NULL ignored    **
-**      Return: NULL if end of file, and no text             **
-**              <text> if there is any, includes blank line  **
-**************************************************************/
-char *frl_line_ncomment(FILE *f, char *comment)
-{
-	char	*str = NULL;
-	char	*ptr = NULL;
-	int	found = 0;
-
-	lines_read = 0;
-
-	while (!found)
-	{
-		/* get the next line of text */
-		str = frl_line(f);
-		lines_read++;
-
-		/* set initial found to true */
-		found = 1;
-
-		/* if EOF then return */
-		if (str != NULL)
-		{
-			/* go through line until first non-space character, or EOL */
-			ptr = str;
-			while ((ptr != NULL) && isspace(*ptr)) ptr++;
-
-			/* EOL, not all spaces */
-			if ((ptr != NULL) && (*ptr != 0))
-			{
-				/* check string for match on comment */
-				if (comment!=NULL && !strncmp(ptr, comment, strlen(comment)))
-				{
-					found = 0;
-					free(str);
-				}
-			}
-		}
-	}
-
-	return(str);
-}
-
-/**************************************************************
 ** Description: repeatedly calls frl from a file until first **
 **              non-blank line not started by given comment  **
 **          In: FILE* to read from - must be open for read   **
@@ -157,412 +109,3 @@
 {
 	return(lines_read);
 }
-
-/**************************************************************
-** Description: searches an ini file for a text string.      **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              <text> if there is any                       **
-**************************************************************/
-char *frl_ini_string(FILE *f, char *comment, char *group, char *entry)
-{
-	char	*text = NULL;
-	char	*gs;
-	char	*ptr = NULL;
-	char	*p2 = NULL;
-	int	found;
-	char	*out;
-	int	len;
-
-	/* go to start of file */
-	rewind(f);
-
-	/* set up string searches */
-	gs = strdup("[");
-	string_add(&gs, group);
-	string_add(&gs, "]");
-
-	/* search down file until correct group is found */
-	found = 0;
-	while (found == 0)
-	{
-		if (text != NULL) free(text);
-		text = frl_line_nspace(f, comment);
-		ptr = text;
-		while ((ptr != NULL) && isspace(*ptr)) ptr++;
-		if (ptr == NULL) found = -1;
-		else if (!strcasecmp(ptr, gs)) found=1;
-	}
-	if (found == -1)
-	{
-		if (text != NULL) free(text);
-		free(gs);
-		return(NULL);
-	}
-
-	/* search for entry until EOF, _or_ a new section heading is found */
-	found = 0;
-	len = strlen(entry);
-	while (found == 0)
-	{
-		if (text != NULL) free(text);
-		text = frl_line_nspace(f, comment);
-		ptr = text;
-		while ((ptr != NULL) && isspace(*ptr)) ptr++;
-		if (ptr == NULL)
-			found = -1;
-		else if (*ptr == '[')
-			found = -1;
-		else if (!strncasecmp(ptr, entry, len))
-			found = 1;
-	}
-	if (found == 1)
-	{
-		p2 = ptr + len;
-		while ((p2 != NULL) && isspace(*p2)) p2++;
-		if (*p2 != '=') found = -1;
-	}
-	if (found == -1)
-	{
-		if (text != NULL) free(text);
-		free(gs);
-		return(NULL);
-	}
-	p2++;
-	while ((p2 != NULL) && isspace(*p2)) p2++;
-	out = strdup(p2);
-
-	/* remove memory used */
-	free(gs);
-	free(text);
-
-	/* return found text entry */
-	return(out);
-}
-
-/**************************************************************
-** Description: returns a list of all matching entries in an **
-**              INI file                                     **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              StringList* if any entries found             **
-**************************************************************/
-StringList *frl_ini_string_list(FILE *f, char *comment, char *group, char *entry)
-{
-	char	*text = NULL;
-	char	*gs;
-	char	*ptr = NULL;
-	char	*p2 = NULL;
-	int	found;
-	int	len;
-	StringList *out = NULL;
-	StringList *new;
-
-	/* go to start of file */
-	rewind(f);
-
-	/* set up string searches */
-	gs = strdup("[");
-	string_add(&gs, group);
-	string_add(&gs, "]");
-
-	/* search down file until correct group is found */
-	found = 0;
-	while (found == 0)
-	{
-		if (text != NULL) free(text);
-		text = frl_line_nspace(f, comment);
-		ptr = text;
-		while ((ptr != NULL) && isspace(*ptr)) ptr++;
-		if (ptr == NULL) found = -1;
-		else if (!strcasecmp(ptr, gs)) found=1;
-	}
-	if (found == -1)
-	{
-		if (text != NULL) free(text);
-		free(gs);
-		return(NULL);
-	}
-
-	/* search for entry until EOF, _or_ a new section heading is found */
-	found = 0;
-	len = strlen(entry);
-	while (found != -1)
-	{
-		if (text != NULL) free(text);
-		text = frl_line_nspace(f, comment);
-		ptr = text;
-		while ((ptr != NULL) && isspace(*ptr)) ptr++;
-		if (ptr == NULL)
-			found = -1;
-		else if (*ptr == '[')
-			found = -1;
-		else if (!strncasecmp(ptr, entry, len))
-		{
-			p2 = ptr + len;
-			while ((p2 != NULL) && isspace(*p2)) p2++;
-			if (*p2 != '=') continue;
-			p2++;
-			while ((p2 != NULL) && isspace(*p2)) p2++;
-			/* p2 is now the string */
-			new = malloc(sizeof(StringList));
-			new->text = strdup(p2);
-			new->next = out;
-			out = new;
-		}
-	}
-	if (out == NULL)
-	{
-		if (text != NULL) free(text);
-		free(gs);
-		return(NULL);
-	}
-
-	/* remove memory used */
-	free(gs);
-	free(text);
-
-	/* return found text entries */
-	return(out);
-}
-
-/**************************************************************
-** Description: frees the memory used by an entry listing    **
-**          In: StringList** the address to the list to be   **
-**              freed.                                       **
-**************************************************************/
-void frl_free_buffer(StringList **sl)
-{
-	StringList *t;
-
-	while (*sl != NULL)
-	{
-		free((*sl)->text);
-		t = *sl;
-		*sl = (*sl)->next;
-		free(t);
-	}
-	*sl = NULL;
-}
-
-/**************************************************************
-** Description: returns a list of all matching entries in an **
-**              INI file                                     **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**      Return: StringList* of ini file                      **
-**************************************************************/
-StringList *frl_buffer_ini(FILE *f, char *comment)
-{
-	StringList *list = NULL;
-	StringList *t;
-	StringList *tail = NULL;
-	char *ptr;
-	char *text;
-	int done = 0;
-
-	while (!done)
-	{
-		text = frl_line_nspace(f, comment);
-		if (text == NULL)
-			done = 1;
-		else
-		{
-			ptr = text;
-			while ((ptr != NULL) && isspace(*ptr)) ptr++;
-			t = malloc(sizeof(StringList));
-			t->text = strdup(ptr);
-			t->next = NULL;
-			free(text);
-			if (list == NULL) {
-				list = t;
-				tail = t;
-			} else {
-				tail->next = t;
-				tail = t;
-			}
-		}
-	}
-	return(list);
-}
-
-/**************************************************************
-** Description: searches an ini file for a text string.      **
-**          In: StringList* file to read from                **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              <text> if there is any                       **
-**************************************************************/
-char *frl_buffer_ini_string(StringList *f, char *group, char *entry)
-{
-	char	*gs;
-	char	*ptr = NULL;
-	char	*p2 = NULL;
-	int	found;
-	int	len;
-	StringList *tf = f;
-
-	/* set up string searches */
-	gs = strdup("[");
-	string_add(&gs, group);
-	string_add(&gs, "]");
-
-	/* search down file until correct group is found */
-	found = 0;
-	while (found == 0)
-	{
-		if (tf==NULL)
-		{
-			found = -1;
-		}
-		else
-		{
-			ptr = tf->text;
-			if (!strcasecmp(ptr, gs)) found=1;
-			tf=tf->next;
-		}
-	}
-	if (found == -1)
-	{
-		free(gs);
-		return(NULL);
-	}
-
-	/* search for entry until EOF, _or_ a new section heading is found */
-	found = 0;
-	len = strlen(entry);
-	while (found == 0)
-	{
-		if (tf==NULL)
-			found = -1;
-		else
-		{
-			ptr = tf->text;
-			while ((ptr != NULL) && isspace(*ptr)) ptr++;
-			if (ptr == NULL)
-				found = -1;
-			else if (*ptr == '[')
-				found = -1;
-			else if (!strncasecmp(ptr, entry, len))
-				found = 1;
-			tf=tf->next;
-		}
-	}
-	if (found == 1)
-	{
-		p2 = ptr + len;
-		while ((p2 != NULL) && isspace(*p2)) p2++;
-		if (*p2 != '=') found = -1;
-	}
-	if (found == -1)
-	{
-		free(gs);
-		return(NULL);
-	}
-	p2++;
-	while ((p2 != NULL) && isspace(*p2)) p2++;
-
-	/* remove memory used */
-	free(gs);
-
-	/* return found text entry */
-	return(strdup(p2));
-}
-
-/**************************************************************
-** Description: returns a list of all matching entries in an **
-**              INI file                                     **
-**          In: StringList* file to read from                **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              StringList* if any entries found             **
-**************************************************************/
-StringList *frl_buffer_ini_string_list(StringList *f, char *group, char *entry)
-{
-	char	*gs;
-	char	*ptr = NULL;
-	char	*p2 = NULL;
-	int	found;
-	int	len;
-	StringList *tf = f;
-	StringList *out = NULL;
-	StringList *new;
-
-	/* set up string searches */
-	gs = strdup("[");
-	string_add(&gs, group);
-	string_add(&gs, "]");
-
-	/* search down file until correct group is found */
-	found = 0;
-	while (found == 0)
-	{
-		if (tf==NULL)
-		{
-			found = -1;
-		}
-		else
-		{
-			ptr = tf->text;
-			if (!strcasecmp(ptr, gs)) found=1;
-			tf=tf->next;
-		}
-	}
-	if (found == -1)
-	{
-		free(gs);
-		return(NULL);
-	}
-
-	/* search for entry until EOF, _or_ a new section heading is found */
-	found = 0;
-	len = strlen(entry);
-
-	while (found != -1)
-	{
-		if (tf==NULL)
-			found = -1;
-		else
-		{
-			ptr = tf->text;
-			while ((ptr != NULL) && isspace(*ptr)) ptr++;
-			if (ptr == NULL)
-				found = -1;
-			else if (*ptr == '[')
-				found = -1;
-			else if (!strncasecmp(ptr, entry, len))
-			{
-				p2 = ptr + len;
-				while ((p2 != NULL) && isspace(*p2)) p2++;
-				if (*p2 != '=') continue;
-				p2++;
-				while ((p2 != NULL) && isspace(*p2)) p2++;
-				/* p2 is now the string */
-				new = malloc(sizeof(StringList));
-				new->text = strdup(p2);
-				new->next = out;
-				out = new;
-			}
-			tf=tf->next;
-		}
-	}
-	if (out == NULL)
-	{
-		free(gs);
-		return(NULL);
-	}
-
-	/* remove memory used */
-	free(gs);
-
-	/* return found text entry */
-	return(out);
-}

Modified: trunk/src/frl.h
===================================================================
--- trunk/src/frl.h	2009-12-12 07:07:56 UTC (rev 1131)
+++ trunk/src/frl.h	2009-12-12 14:36:46 UTC (rev 1132)
@@ -22,20 +22,7 @@
 char *frl_line(FILE *f);
 
 
-
 /**************************************************************
-** Description: repeatedly calls frl from a file until the   **
-**              first lineno starting in the given comment   **
-**          In: FILE* to read from - must be open for read   **
-**              char* comment to ignore - if NULL ignored    **
-**      Return: NULL if end of file, and no text             **
-**              <text> if there is any, includes blank line  **
-**************************************************************/
-char *frl_line_ncomment(FILE *f, char *comment);
-
-
-
-/**************************************************************
 ** Description: repeatedly calls frl from a file until first **
 **              non-blank line not started by given comment  **
 **          In: FILE* to read from - must be open for read   **
@@ -48,77 +35,3 @@
 
 long num_lines_read(void);
 
-
-/**************************************************************
-** Description: searches an ini file for a text string.      **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              <text> if there is any                       **
-**************************************************************/
-char *frl_ini_string(FILE *f, char *comment, char *group, char *entry);
-
-
-
-/**************************************************************
-** Description: returns a list of all matching entries in an **
-**              INI file                                     **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              StringList* if any entries found             **
-**************************************************************/
-StringList *frl_ini_string_list(FILE *f, char *comment, char *group, char *entry);
-
-
-
-/**************************************************************
-** Description: frees the memory used by an entry listing    **
-**          In: StringList** the address to the list to be   **
-**              freed.                                       **
-**************************************************************/
-void frl_free_buffer(StringList **sl);
-
-
-
-
-/**************************************************************
-** Description: returns a list of all matching entries in an **
-**              INI file                                     **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**      Return: StringList* of ini file                      **
-**************************************************************/
-StringList *frl_buffer_ini(FILE *f, char *comment);
-
-
-
-
-/**************************************************************
-** Description: searches an ini file for a text string.      **
-**          In: StringList* file to read from                **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              <text> if there is any                       **
-**************************************************************/
-char *frl_buffer_ini_string(StringList *f, char *group, char *entry);
-
-
-
-
-/**************************************************************
-** Description: returns a list of all matching entries in an **
-**              INI file                                     **
-**          In: FILE* file to read from                      **
-**              char* comment to ignore - if NULL ignored    **
-**              char* group heading to search under          **
-**              char* entry name to return value for         **
-**      Return: NULL if given entry, or file are not found   **
-**              StringList* if any entries found             **
-**************************************************************/
-StringList *frl_buffer_ini_string_list(StringList *f, char *group, char *entry);

Modified: trunk/src/rooms.c
===================================================================
--- trunk/src/rooms.c	2009-12-12 07:07:56 UTC (rev 1131)
+++ trunk/src/rooms.c	2009-12-12 14:36:46 UTC (rev 1132)
@@ -77,167 +77,6 @@
 	return 1;
 }
 
-void room_who_list(void)
-{
-	struct person u;
-	struct who w;
-	int ufile,wfile;
-	char *str;
-	char chat;
-
-	busy++;
-
-	wfile=openwhofile(O_RDONLY);
-	ufile=openuserfile(O_RDONLY);
-	if (wfile<0 || ufile<0) return; /* whoops */
-
-	str=strdup("");
-
-	while (read(wfile,&w,sizeof(w)))
-	{
-		/* Skip invalid entries */
-		if (w.posn < 0)
-			continue;
-
-		lseek(ufile,w.posn,0);
-		read(ufile,&u,sizeof(u));
-
-		/* check they are still alive and show info */
-		if (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL))
-		{
-			if (cm_flags(u.chatmode,CM_ONCHAT,CM_MODE_ANY))
-			{
-				if ((u.room == user->room) && strcmp(u.name, user->name))
-				{
-					if (str != NULL && *str != 0)
-					{
-						str = realloc(str, sizeof(char) * (strlen(str) + 3));
-						strcat(str, ", ");
-					}
-					chat = 0;
-					if ((u_god(u.status) || s_wizchat(u.special)) && !s_chatoff(u.special))
-						chat = '*';
-					if (chat==0)
-					{
-						str = realloc(str, sizeof(char) * (strlen(u.name) + strlen(str) + 1));
-						strcat(str, u.name);
-					}
-					else
-					{
-						strcatc(&str, chat);
-						str = realloc(str, sizeof(char) * (strlen(u.name) + strlen(str) + 1));
-						strcat(str, u.name);
-					}
-				}
-			}
-		}
-	}
-	
-	if (!strcmp(str, ""))
-	{
-		display_message("\03319There is no-one else in here...", 0, 1);
-	}
-	else
-	{
-		char buff[2048];
-
-		display_message("\03319In here, you can also see:-", 0, 1);
-		snprintf(buff, 2047, "\03319%s", str);
-		display_message(buff, 0, 1);
-	}
-	close(wfile);
-	close(ufile);
-
-	busy--;
-
-	free(str);
-}
-
-void talker_who(int mode)
-{
-	struct person	u;
-	struct who	w;
-	int		ufile,wfile;
-	struct room	room;
-	char		line[82];
-	char		*divider;
-	int		index;
-
-	busy++;
-	
-	wfile=openwhofile(O_RDONLY);
-	ufile=openuserfile(O_RDONLY);
-	if (wfile<0 || ufile<0) return; /* whoops */
-
-	if (mode == 1)
-	snprintf(line,81, "%-*s  Since  Status...\n", NAMESIZE, "Name" );
-	else
-	snprintf(line,81, "%-*s   Idle  Room Description...\n", NAMESIZE, "Name" );
-	display_message("\n", 0, 1);
-	display_message(line, 0, 1);
-
-	divider = NULL;
-	for (index = 0; index < screen_w(); index++) string_add(&divider, "-");
-	string_add(&divider, "\n");
-
-	display_message(divider, 0, 1);
-
-	while (read(wfile,&w,sizeof(w)))
-	{
-		/* Skip invalid entries */
-		if (w.posn < 0)
-			continue;
-
-		lseek(ufile,w.posn,0);
-		read(ufile,&u,sizeof(u));
-
-		/* check they are still alive and show info */
-		if (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL))
-		{
-			char *label;
-
-			RoomInit(&room);
-			if (cm_flags(u.chatmode,CM_ONCHAT,CM_MODE_ANY))
-			{
-				if (!LoadRoom(&room, u.room))
-				{
-					label=strdup("-----");
-					room.num=u.room;
-				}
-				else if (room.prompt!=NULL)
-					label=strdup(room.prompt);
-				else
-					label=strdup(room.name);
-			}else {
-				label=malloc(56);
-				snprintf(label, 55, "Not On Talker");
-			}
-
-			if (mode == 1) 
-				snprintf(line, 81, "%-*s %6s %s %s\n", NAMESIZE, u.name, itime(time(0)-u.dowhen), u.name, u.doing);
-			else
-			if (room.num==-1)
-				snprintf(line, 81, "%-*s %6s ***** %.54s\n", NAMESIZE, u.name, itime(time(0)-u.idletime), label);
-			else if (room.hidden>0)
-				snprintf(line, 81, "%-*s %6s ----- %.54s\n", NAMESIZE, u.name, itime(time(0)-u.idletime), label);
-			else
-				snprintf(line, 81, "%-*s %6s %5d %.45s\n", NAMESIZE, u.name, itime(time(0)-u.idletime), room.num, label);
-
-			RoomDestroy(&room);
-			free(label);
-			display_message(line, 0, 1);
-		}
-	}
-
-	display_message(divider, 0, 1);
-	close(wfile);
-	close(ufile);
-
-	free(divider);
-
-	busy--;
-}
-
 /* changes room, returning error code on failure
  * 0 - ok
  * 1 - hidden/locked

Modified: trunk/src/rooms.h
===================================================================
--- trunk/src/rooms.h	2009-12-12 07:07:56 UTC (rev 1131)
+++ trunk/src/rooms.h	2009-12-12 14:36:46 UTC (rev 1132)
@@ -2,6 +2,4 @@
 void RoomInit(struct room *room);
 void RoomDestroy(struct room *room);
 int LoadRoom(struct room *room, int num);
-void talker_who(int mode);
-void room_who_list(void);
 int ChangeRoom(char *room, int quiet);

Modified: trunk/src/sqlite.c
===================================================================
--- trunk/src/sqlite.c	2009-12-12 07:07:56 UTC (rev 1131)
+++ trunk/src/sqlite.c	2009-12-12 14:36:46 UTC (rev 1132)
@@ -160,6 +160,8 @@
 	if(new->query_result == NULL) {
 		new->error_text=strdup("malloc error for query result");
 		new->db_error=-3;
+		db_close(db);
+		return new;
 	}
 	
 	new->query_result->rows = -1;
@@ -205,39 +207,6 @@
 	return ndata->field[col];
 }
 
-
-/* fetch a row, return it as a struct */
-void db_getrow(struct db_result *result, int *row)
-{
-	struct db_data *ndata;
-	char **field_names;
-	unsigned char *field_types;
-	void **field_values;
-	int i;
-
-	if (result == NULL) return;
-
-	if (*row < 0 || *row >= result->rows) return;
-
-	ndata = result->data;
-	while (ndata!=NULL && ndata->row != *row) ndata=ndata->next;
-
-	if (ndata == NULL) {
-		printf("Failed to find row %d of result.\n", *row);
-		return;
-	}
-	field_names = calloc(result->cols, sizeof(char *));
-        field_types = calloc(result->cols, sizeof(unsigned char));
-        field_values = calloc(result->cols, sizeof(char *));
-
-	for (i=0;i<result->cols;i++) {
-		field_names[i] = result->colNames[i];
-		/* field_types[i] = SLANG_STRING_TYPE; TODO: remove slangism */
-		field_values[i] = &(ndata->field[i]);
-	}
-	/* SLstruct_create_struct(result->cols, field_names, field_types, field_values); */
-}
-
 void db_free(struct db_result *result)
 {
 	struct db_data *ndata, *nnext;

Modified: trunk/src/sqlite.h
===================================================================
--- trunk/src/sqlite.h	2009-12-12 07:07:56 UTC (rev 1131)
+++ trunk/src/sqlite.h	2009-12-12 14:36:46 UTC (rev 1132)
@@ -22,7 +22,6 @@
 
 struct db_result *db_query(char *dbname, char *query, int quiet);
 struct js_db_result* js_db_query(char *dbname, char *query);
-void db_getrow(struct db_result *result, int *row);
 void db_free(struct db_result *result);
 void js_db_free(struct js_db_result *result);
 char * db_item(struct db_result *result, int row, const char *field);




More information about the mw-devel mailing list