1. tm512
  2. ispolin

Commits

tm512  committed 30062cf

Fix segfault that would happen on exit if no channels were specified for a server.
Clean up arg parsing a bit.

  • Participants
  • Parent commits 463ca8d
  • Branches master

Comments (0)

Files changed (2)

File src/irc.c

View file
 	free (cl->rbuf);
 
 	chanlist_t *it = cl->channels;
-	while (1)
-	{
-		chanlist_t *next = it->next;
-		free (it);
-		if (next)
-			it = next;
-		else
-			break;
-	}
+	if (it)
+		while (1)
+		{
+			chanlist_t *next = it->next;
+			free (it);
+			if (next)
+				it = next;
+			else
+				break;
+		}
 
 	free (cl);
 	*clp = NULL;

File src/main.c

View file
 char *configpath = "./config.lua";
 config_t globalcfg;
 
+#define argif(longform,shortform) if (!strcmp (argv [i], longform) || !strcmp (argv [i], shortform))
+
 void parseargs (int argc, char **argv)
 {
 	int i;
 	for (i = 1; i < argc; i++)
 	{
-		int arglen = strlen (argv [i]);
-		if (!strcmp (argv [i], "--config") || !strcmp (argv [i], "-c"))
+		argif ("--config", "-c")
 		{
-			configpath = argv [i + 1];
+			if (i + 1 < argc && argv [i + 1] [0] != '-')
+				configpath = argv [i + 1];
 			continue;
 		}
 
-		if (!strcmp (argv [i], "--daemon") || !strcmp (argv [i], "-d"))
+		argif ("--daemon", "-d")
 		{
 			pid_t pid;
 			FILE *pidfile = NULL;
 	return;
 }
 
+#undef argif
+
 // Kills off all connections
 void die (char *msg)
 {