changeset 8955:2454bcd4c3f3

sanity checks - patch by Fabian Franz <FabianFranz@gmx.de> cache results of strchr() calls
author arpi
date Tue, 14 Jan 2003 23:15:36 +0000
parents 75048549dc44
children 9787abc8039e
files libmpdemux/tv.c
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/tv.c	Tue Jan 14 22:03:15 2003 +0000
+++ b/libmpdemux/tv.c	Tue Jan 14 23:15:36 2003 +0000
@@ -245,15 +245,18 @@
 
 	while (*tv_param_channels) {
 		char* tmp = *(tv_param_channels++);
+		char* sep = strchr(tmp,'-');
 		int i;
 		struct CHANLIST cl;
 
-		strcpy(tv_channel_current->name, strchr(tmp, '-') + 1);
-		strchr(tmp, '-')[0] = '\0';
+		if (!sep) continue; // Wrong syntax, but mplayer should not crash
+
+		strcpy(tv_channel_current->name, sep + 1);
+		sep[0] = '\0';
 		strncpy(tv_channel_current->number, tmp, 5);
 
-		while (strchr(tv_channel_current->name, '_'))
-			strchr(tv_channel_current->name, '_')[0] = ' ';
+		while ((sep=strchr(tv_channel_current->name, '_')))
+		    sep[0] = ' ';
 
 		tv_channel_current->freq = 0;
 		for (i = 0; i < chanlists[tvh->chanlist].count; i++) {
@@ -277,8 +280,8 @@
 		tv_channel_current->next->next = NULL;
 		tv_channel_current = tv_channel_current->next;
 	}
-
-	tv_channel_current->prev->next = NULL;
+	if (tv_channel_current->prev)
+  	  tv_channel_current->prev->next = NULL;
 	free(tv_channel_current);
     } else 
 	    tv_channel_last_real = malloc(sizeof(char)*5);