[Pinfo-devel] r129 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Fri Sep 2 04:46:50 UTC 2005
Author: neroden-guest
Date: 2005-09-02 04:46:50 +0000 (Fri, 02 Sep 2005)
New Revision: 129
Modified:
pinfo/branches/cxx/src/filehandling_functions.cxx
Log:
First pass at cleaning up infopaths; leaks memory but works.
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-02 04:25:08 UTC (rev 128)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-02 04:46:50 UTC (rev 129)
@@ -817,13 +817,13 @@
initpaths()
{
char **paths = NULL;
- char *langpath = NULL;
char *rawlang = NULL;
string lang;
string langshort;
char* c;
int ret;
- unsigned int i, j, maxpaths, numpaths = 0, langlen;
+ unsigned int i, j, maxpaths;
+ unsigned int numpaths = 0;
size_t len;
struct stat sbuf;
ino_t *inodes;
@@ -877,36 +877,25 @@
}
/* if we have a LANG defined, add paths with this lang to the paths[] */
- if (lang != "")
- {
- /* crude upper limit */
- langlen = strlen(env) + configuredinfopath.length() + 2
- + (lang.length()+2) * numpaths + 1;
- if (langshort != "") langlen *= 2;
- langpath = (char *) xmalloc( langlen * sizeof(char) );
-
- c = langpath;
- for (i=0; i<numpaths; i++)
- {
- /* TODO: check for negative return values of sprintf */
- len = sprintf(c, "%s/%s", paths[i], lang.c_str());
+ if (lang != "") {
+ /* Leak memory with strdup; FIXME */
+ for (i=0; i<numpaths; i++) {
+ string tmp;
+ tmp = paths[i];
+ tmp += '/';
+ tmp += lang;
/* add the lang specific dir at the beginning */
paths[numpaths+i] = paths[i];
- paths[i] = c;
-
- c += len+1;
+ paths[i] = strdup(tmp.c_str());
- if (langshort != "")
- {
- /* TODO: check for negative return values of sprintf */
- len = sprintf(c, "%s/%s", paths[numpaths+i], langshort.c_str());
- /* add the lang specific dir at the beginning */
+ if (langshort != "") {
+ string tmp;
+ tmp = paths[i];
+ tmp += '/';
+ tmp += langshort;
paths[2*numpaths+i] = paths[numpaths+i];
- paths[numpaths+i] = c;
-
- c += len+1;
+ paths[numpaths+i] = strdup(tmp.c_str());
}
-
}
numpaths *= ( (langshort!="") ? 3 : 2);
}
@@ -972,7 +961,6 @@
}
}
- xfree(langpath);
xfree(paths);
xfree(inodes);
More information about the Pinfo-devel
mailing list