[Pinfo-devel] r184 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Wed Sep 7 01:55:46 UTC 2005
Author: neroden-guest
Date: 2005-09-07 01:55:45 +0000 (Wed, 07 Sep 2005)
New Revision: 184
Modified:
pinfo/branches/cxx/src/filehandling_functions.cxx
Log:
Fix my off-by-one errors, do some bounds checking, and finish merging the
changes in trunk in revision 179.
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-07 01:40:25 UTC (rev 183)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-07 01:55:45 UTC (rev 184)
@@ -217,8 +217,8 @@
&& (this_line.length() != nameend + 1)
&& (this_line[nameend + 1] != ':')
&& ( (filestart = this_line.find('(', nameend + 1)) != string::npos )
- && ( (fileend = this_line.find(')', filestart)) != string::npos )
- && ( (dot = this_line.find('.', fileend)) != string::npos )
+ && ( (fileend = this_line.find(')', filestart + 1)) != string::npos )
+ && ( (dot = this_line.find('.', fileend + 1)) != string::npos )
) {
; /* Matches the pattern we want */
} else {
@@ -227,13 +227,15 @@
/* It looks like a match. */
string name(this_line, 2, nameend - 2);
- string file(this_line, filestart + 1, fileend - filestart - 2);
- string node(this_line, fileend + 1, dot - fileend - 2);
+ string file(this_line, filestart + 1, fileend - (filestart + 1) );
+ string node(this_line, fileend + 1, dot - (fileend + 1) );
- if (strcasecmp(wanted_name.c_str(),
- name.substr(0, wanted_name.length()).c_str())
- != 0) {
- /* Wrong name -- wanted_name must begin the name */
+ if ( (name.length() >= wanted_name.length())
+ && (strcasecmp(wanted_name.c_str(),
+ name.substr(0, wanted_name.length()).c_str()) == 0)
+ ) {
+ ; /* Wanted_name begins the name, so it's a match */
+ } else {
continue;
}
@@ -252,22 +254,25 @@
}
if (id) {
+ /* Close the previously opened file */
fclose(id);
- /* Close the previously opened file */
+ id = 0;
}
- id = 0;
if (file.find(".info") == string::npos) {
file += ".info";
}
+
+ /* See if this info file exists, and open it if it does */
id = openinfo(file, 0);
- /* See if this info file exists */
- goodHit = true;
- if ((nameend - 2) == wanted_name.length()) {
+ if (id) {
+ goodHit = true;
+ if ((nameend - 2) == wanted_name.length()) {
/* the name matches perfectly to the query */
/* stop searching for another match, and use this one */
break;
}
+ }
}
/* if we haven't found anything, clean up and exit */
More information about the Pinfo-devel
mailing list