Re: Debian backend update



Colin Walters wrote:
Err, surely just: ret->name = g_strdup (name) ?

Never done much glib programming... that does make life a lot easier.

You aren't checking for inp being NULL.

I've attached a patch that puts in the g_strdup's, checks for inp being NULL, and also switches to using syslog(LOG_ERROR,"whatever error") rather than fprintf(stderr,...). Thanks to whoever put in the standard license stuff on my files BTW.

Tom
--
palfrey tevp net - http://tevp.net
Illegitimus non carborundum
? cleanup.patch
Index: interface_parser.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/backends/interface_parser.c,v
retrieving revision 1.1
diff -u -r1.1 interface_parser.c
--- interface_parser.c	11 Nov 2004 02:24:04 -0000	1.1
+++ interface_parser.c	11 Nov 2004 11:11:37 -0000
@@ -34,10 +34,8 @@
 void add_block(const char *type, const char* name)
 {
 	if_block *ret = (if_block*)calloc(1,sizeof(struct _if_block));
-	ret->name = (char*)calloc(strlen(name),sizeof(char));
-	strcpy(ret->name, name);
-	ret->type = (char*)calloc(strlen(type),sizeof(char));
-	strcpy(ret->type, type);
+	ret->name = g_strdup(name);
+	ret->type = g_strdup(type);
 	if (first == NULL)
 		first = last = ret;
 	else
@@ -52,10 +50,8 @@
 void add_data(const char *key,const char *data)
 {
 	if_data *ret = (if_data*)calloc(1,sizeof(struct _if_data));
-	ret->key = (char*)calloc(strlen(key),sizeof(char));
-	strcpy(ret->key,key);
-	ret->data = (char*)calloc(strlen(data),sizeof(char));
-	strcpy(ret->data, data);
+	ret->key = g_strdup(key);
+	ret->data = g_strdup(data);
 	
 	if (last->info == NULL)
 	{
@@ -74,6 +70,11 @@
 {
 	FILE *inp = fopen(INTERFACES,"r");
 	int ret = 0;
+	if (inp == NULL)
+	{
+		syslog (LOG_ERR, "Error: Can't open %s\n",INTERFACES);
+		return;
+	}
 	first = last = NULL;
 	while(1)
 	{
@@ -90,7 +91,7 @@
 		space = strchr(line,' ');
 		if (space == NULL)
 		{
-			fprintf(stderr,"Can't parse line '%s'\n",line);
+            syslog (LOG_ERR, "Error: Can't parse interface line '%s'\n",line);
 			continue;
 		}
 		space[0] = '\0';
@@ -101,7 +102,7 @@
 			char *space2 = strchr(space+1,' ');
 			if (space2 == NULL)
 			{
-				fprintf(stderr,"Can't parse iface line '%s'\n",space+1);
+            	syslog (LOG_ERR, "Error: Can't parse interface line '%s'\n",space+1);
 				continue;
 			}
 			space2[0]='\0';
@@ -112,7 +113,7 @@
 				space = strchr(space2+1,' ');
 				if (space == NULL)
 				{
-					fprintf(stderr,"Can't parse data '%s'\n",space2+1);
+            		syslog (LOG_ERR, "Error: Can't parse data '%s'\n",space2+1);
 					continue;
 				}
 				space[0] = '\0';


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]