Package: webcpp
Version: 0.8.4-5
Severity: minor
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This bug was reported by Thanassis Tsiodras:

Hi Roberto.

I use webcpp to automatically color the code snippets in my site...
and I found out that webcpp has a bug when a keyword appears
at the beginning of a line

(I have some Python code, where for example the functions are
defined with a "def" starting at the beginning of the line)

If you check the code in Engine.cpp, (version 0.8.4), you'll see
that when locating a keyword, parseKeys() is calling isKey() with

if(isKey(index-1, (index) + keys[i].size())) {

If the keyword appears at the beginning of the line (e.g. "def" in
Python code), then this causes member isKey to operate on
buffer[-1]...

I did this patch which seems to correct the problems with Python code...

Regards,
Thanassis.


- -- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-6-k7
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIkdCL5SXWIKfIlGQRAmetAJoD/sXVFS1/U00oLUDCXAG8mRgDYQCgjuo/
kbPhQl397bi/erf1LeVzbyc=
=kvst
-----END PGP SIGNATURE-----
--- engine.cpp  Mon Jan  5 02:52:47 2004
+++ engine.cpp.fixed    Sat Jul 26 20:17:41 2008
@@ -697,16 +697,23 @@
 // asserts word boundaries for keywords ---------------------------------------
 bool Engine::isKey(int before, int after) const {

-       if(buffer[before] == '#')   {return false;}
-       if(buffer[before] == '_')   {return false;}
-       if(buffer[after]  == '_')   {return false;}
-       if(isalnum(buffer[before])) {return false;}
-       if(isalnum(buffer[after]))  {return false;}
+       if (before>=0 && before<buffer.size()) {
+               if(buffer[before] == '#')   {return false;}
+               if(buffer[before] == '_')   {return false;}
+       }
+       if (after>=0 && after<buffer.size())
+               if(buffer[after]  == '_')   {return false;}
+       if (before>=0 && before<buffer.size())
+               if(isalnum(buffer[before])) {return false;}
+       if (after>=0 && after<buffer.size())
+               if(isalnum(buffer[after]))  {return false;}

-       if(ispunct(buffer[before]) || isspace(buffer[before])) {
-               if(ispunct(buffer[after]) || isspace(buffer[after])) {
+       if (before>=0 && before<buffer.size())
+           if(ispunct(buffer[before]) || isspace(buffer[before])) {
+               if (after>=0 && after<buffer.size())
+                   if(ispunct(buffer[after]) || isspace(buffer[after])) {
                        return true;
-               }
+                   }
        }
        return true;
 }

Reply via email to