[Pinfo-devel] r75 - pinfo/branches/cxx/src

Nathanael Nerode neroden-guest at costa.debian.org
Tue Aug 30 06:39:46 UTC 2005


Author: neroden-guest
Date: 2005-08-30 06:39:44 +0000 (Tue, 30 Aug 2005)
New Revision: 75

Modified:
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/mainfunction.cxx
Log:
More low-hanging fruit; eliminate most instances of strcat


Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-30 06:27:21 UTC (rev 74)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-30 06:39:44 UTC (rev 75)
@@ -793,11 +793,11 @@
 {
 	char emptystr[1] = "";
 	char **paths = NULL;
-	char *infopath = NULL, *langpath = NULL;
+	char *langpath = NULL;
 	char *c, *dir, *env;
 	char *rawlang = NULL, *lang = NULL, *langshort = NULL;
 	int ret;
-	unsigned int i, j, maxpaths, numpaths = 0, infolen, langlen;
+	unsigned int i, j, maxpaths, numpaths = 0, langlen;
 	size_t len;
 	struct stat sbuf;
 	ino_t *inodes;
@@ -808,18 +808,17 @@
 	{
 		env = emptystr;
 	}
-	infolen = strlen(env) + configuredinfopath.length() + 2;
-	infopath = (char *) xmalloc( infolen );
-	strcat(infopath, env);
-	strcat(infopath, ":");
-	strcat(infopath, configuredinfopath.c_str());
+	string infopath;
+	infopath = env; 
+	infopath += ":"; /* FIXME: what if one of the two is blank? */
+	infopath += configuredinfopath;
 
 	/* alloc the paths[] array */
-	maxpaths = 3 * (charcount( infopath, ':' ) + 1); // *3 for $LANG
+	maxpaths = 3 * (charcount( infopath.c_str(), ':' ) + 1); // *3 for $LANG
 	paths = (char **) xmalloc( maxpaths * sizeof(char *) );
 
 	/* split at ':' and put the path components into paths[] */
-	c = infopath;
+	c = strdup(infopath.c_str());
 	while ((dir = strsep(&c, ":")))
 	{
 		/* if this actually is a non-empty string, add it to paths[] */
@@ -828,6 +827,7 @@
 			paths[numpaths++] = dir;
 		}
 	}
+	xfree(c);
 
 	/* get the current $LANG, if any (to use for localized info pages) */
 	rawlang = getenv("LANG");
@@ -853,7 +853,8 @@
 	if (lang && strlen(lang)>0 )
 	{
 		/* crude upper limit */
-		langlen = infolen + (strlen(lang)+2) * numpaths + 1;
+		langlen = strlen(env) + configuredinfopath.length() + 2
+						  + (strlen(lang)+2) * numpaths + 1;
 		if (langshort!=NULL) langlen *= 2;
 		langpath = (char *) xmalloc( langlen * sizeof(char) );
 
@@ -945,7 +946,6 @@
 	}
 	
 
-	xfree(infopath);
 	xfree(langpath);
 	xfree(paths);
 	xfree(lang);

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-08-30 06:27:21 UTC (rev 74)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-08-30 06:39:44 UTC (rev 75)
@@ -1016,37 +1016,31 @@
 						{
 							if (hyperobjects[cursor].type == 4)	/* http */
 							{
-								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + httpviewer.length() + 10);
-								strcpy(tempbuf, httpviewer.c_str());
-								strcat(tempbuf, " ");
-								strcat(tempbuf, hyperobjects[cursor].node.c_str());
+								string tempbuf = httpviewer;
+								tempbuf += " ";
+								tempbuf += hyperobjects[cursor].node;
 								myendwin();
-								system(tempbuf);
+								system(tempbuf.c_str());
 								doupdate();
-								xfree(tempbuf);
 							}
 							else if (hyperobjects[cursor].type == 5)	/* ftp */
 							{
-								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + ftpviewer.length() + 10);
-								strcpy(tempbuf, ftpviewer.c_str());
-								strcat(tempbuf, " ");
-								strcat(tempbuf, hyperobjects[cursor].node.c_str());
+								string tempbuf = ftpviewer;
+								tempbuf += " ";
+								tempbuf += hyperobjects[cursor].node;
 								myendwin();
-								system(tempbuf);
+								system(tempbuf.c_str());
 								doupdate();
-								xfree(tempbuf);
 							}
 							else if (hyperobjects[cursor].type == 6)	/* mail */
 							{
-								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + maileditor.length() + 10);
-								strcpy(tempbuf, maileditor.c_str());
-								strcat(tempbuf, " ");
-								strcat(tempbuf, hyperobjects[cursor].node.c_str());
+								string tempbuf = maileditor;
+								tempbuf += " ";
+								tempbuf += hyperobjects[cursor].node;
 								myendwin();
 								system("clear");
-								system(tempbuf);
+								system(tempbuf.c_str());
 								doupdate();
-								xfree(tempbuf);
 							}
 						}
 					}




More information about the Pinfo-devel mailing list