[Pinfo-devel] r293 - pinfo/trunk/src
Bas Zoetekouw
bas at costa.debian.org
Wed Mar 15 12:32:10 UTC 2006
Author: bas
Date: 2006-03-15 12:32:09 +0000 (Wed, 15 Mar 2006)
New Revision: 293
Modified:
pinfo/trunk/src/mainfunction.c
pinfo/trunk/src/manual.c
pinfo/trunk/src/utils.c
Log:
Fixed a segfault caused by highlighting of a regular expression that failed to
compile. Regexps that turn out to be faulty are now no longer stored in the
history. Thanks to Jelmer Vernooij for noticing this.
Modified: pinfo/trunk/src/mainfunction.c
===================================================================
--- pinfo/trunk/src/mainfunction.c 2006-03-15 12:10:52 UTC (rev 292)
+++ pinfo/trunk/src/mainfunction.c 2006-03-15 12:32:09 UTC (rev 293)
@@ -571,6 +571,8 @@
/* compile the read token */
if (pinfo_re_comp(token) != 0)
{
+ /* we're not in a search! */
+ aftersearch = 0;
/* print error message */
attrset(bottomline);
mymvhline(maxy - 1, 0, ' ', maxx);
Modified: pinfo/trunk/src/manual.c
===================================================================
--- pinfo/trunk/src/manual.c 2006-03-15 12:10:52 UTC (rev 292)
+++ pinfo/trunk/src/manual.c 2006-03-15 12:32:09 UTC (rev 293)
@@ -1146,6 +1146,8 @@
/* compile regexp expression */
if (pinfo_re_comp(token) != 0)
{
+ /* We're not in a search! */
+ aftersearch = 0;
/* print error message */
attrset(bottomline);
mymvhline(maxy - 1, 0, ' ', maxx);
Modified: pinfo/trunk/src/utils.c
===================================================================
--- pinfo/trunk/src/utils.c 2006-03-15 12:10:52 UTC (rev 292)
+++ pinfo/trunk/src/utils.c 2006-03-15 12:32:09 UTC (rev 293)
@@ -395,6 +395,16 @@
pinfo_re_pattern = strdup(name);
return 0;
#else
+ /* first see if we can compile the regexp */
+ regex_t preg;
+ if (regcomp(&preg, name, REG_ICASE) != 0)
+ {
+ /* compilation failed, so return */
+ return -1;
+ }
+
+ /* compilation succeeded */
+ /* first make some space in h_regexp[] to store the compiled regexp */
if (pinfo_re_offset == -1)
{
pinfo_re_offset = h_regexp_num;
@@ -407,7 +417,12 @@
{
regfree(&h_regexp[pinfo_re_offset]);
}
- return regcomp(&h_regexp[pinfo_re_offset], name, REG_ICASE);
+
+ /* then copy the compiled expression into the newly allocated space */
+ memcpy(&h_regexp[pinfo_re_offset], &preg, sizeof(preg));
+
+ /* and finally return 0 for success */
+ return 0;
#endif
}
More information about the Pinfo-devel
mailing list