sparse tool handling of escaped characters in strings

sparse tool handling of escaped characters in strings

Post by Dave Olie » Sat, 31 May 2003 00:40:12

Hi, Linus.  I'm just beginning to look over your sparse tool library.
I decided to start with something simple.  Running your check tool
on the 2.5.70 kernel produces 25 warnings of the forms:

warning: drivers/char/n_tty.c:198:35: Unknown escape 'r'
warning: drivers/char/n_tty.c:225:11: Unknown escape 'b'
warning: drivers/char/n_tty.c:547:17: Unknown escape 'a'

They come from character strings that contain escaped characters that
escapechar() in tokenize.c didn't recognize. I added cases for these

The warning below is a little more interesting.

warning: fs/proc/array.c:338:1: Unknown escape '

It comes from a string that is continued on multiple lines, of the form:


This is different from the other cases because the \<newline> character should
never appear in the parsed string.

As a first fix, I've made escapechar() call itself recursively.
One flaw with this fix is that escapechar() will mark the first character on
the second line of the input string as "escaped":

        /* Mark it as escaped */
        value |= 0x100;

But, none of the callers to escapechar() ever use or preserve this information.
Can this "escaped" character information be removed.

Or, I could add a flag (ugh) that causes the code to NOT add the
escape flag in this particular case.

Or, I could find a different solution to this case.

Dave Olien


--- sparse_original/tokenize.c  2003-05-29 14:22:20.000000000 -0700

                next = nextchar(stream);
                if (value != type) {
                        switch (value) {
-                       case 'n':
-                               value = '\n';
+                       case 'a':
+                               value = '\a';
+                               break;
+                       case 'b':
+                               value = '\b';
                        case 't':
                                value = '\t';
+                       case 'n':
+                               value = '\n';
+                               break;
+                       case 'v':
+                               value = '\v';
+                               break;
+                       case 'f':
+                               value = '\f';
+                               break;
+                       case 'r':
+                               value = '\r';
+                               break;
+                       case 'e':
+                               value = '\e';
+                               break;
                        case '\\':
                        case '\'':
                        case '"':
+                       case '\n':
+                               next = escapechar(next, type, stream, &value);
+                               break;
                        case '0'...'7': {
                                int nr = 2;
                                value -= '0';
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at
Please read the FAQ at


1. Handling escaped characters.

What is the best way to handle escaped characters?
Both in general and in specific cases.

A few specific cases:

case  --  I don't want it to process escaped '-' as part of options.
 ie (this is what I WANT):
   $ function YES_OR_NO
         case $1 in
          -a) echo YES   ;;
          a)  echo NO    ;;
          *)  echo MAYBE ;;
   $ YES_OR_NO '-a'
   $ YES_OR_NO '\-a'
   $ YES_OR_NO '\a'
   $ YES_OR_NO '-\a'
   $ YES_OR_NO '\-\a'
   $ YES_OR_NO '\\\-a'


Parameter substitution; ie:
   $ abc='\teTtp\\T\r3'
   $ echo "$abc"
   $ echo "${abc//t/#}"

But what I want is something like:
   $ abc='\teTtp\\T\r3'
   $ de_escape "$abc"         ## "De-Escapes";  Note: Doesn't remove
escaped escape
   $ replace "$abc" 't'  X    ## Replaces non-escaped versions.
   $ replace "$abc" '\t' X    ## '\t' does not match with 't'

If you notice, in the first example, anything but a '-' should not be
affected by an escape.  However, in the second example, any character
that is escaped should be treated differently.

Essentially, what I want is 3 things:
1.      function de_escape ():    removes escapes
2.      A modification io case "$1" that will support  escapes as above
3.      A replacement for "${var//str1}" that supports escapes as above

I am not asking for anyone to write this for me (although I wouldn't
mind it if someone would).  I need some pointers on how I should go
about this.  I have some ideas on "workarounds", but there is nothing
even moderately fast that I can make that doesn't have a ton of bugs.

Speed and accuracy are REALLY impartant for this.  I want something
similar to the way command line options are processed on many basic

Thank you in advance for any help.

2. program ld got fatal signal 6

3. Escape special characters in a string

4. SiS 900 problem - FreeBSD 4.5 RELEASE

5. looking for an escape function (ansi c) to escape characters for usage in an URL

6. internal modem problem

7. Hole (sparse file) handling changed?

8. trying to buy an unix box

9. Make sparse-able files sparse

10. Gnu Tar (1.11.2) handling sparse files

11. gtar -S handles sparse files improperly

12. escape $ in ppp chat password string

13. need help with escapes in prompt strings