Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 275 times

Contents

Related Categories

The use of the code analysis library OpenC++: modifications, improvements, error corrections - 16. Correction of the error occurring while analyzing "#line" directive.

AndreyKarpov

16. Correction of the error occurring while analyzing "#line" directive.

In some cases Program::ReadLineDirective() function glitches taking irrelevant text for "#line" directive. The corrected variant of the function looks as follows:

ptrdiff_t Program::ReadLineDirective(size_t i,
  ptrdiff_t line_number,
  size_t& filename, size_t& filename_length) const
{
    char c;
    do{
        c = Ref(++i);
    } while(is_blank(c));
#if defined(_MSC_VER) || defined(IRIX_CC)
    if(i + 5 <= GetSize() &&
       strncmp(Read(i), "line ", 5) == 0) {
        i += 4;
        do{
          c = Ref(++i);
        }while(is_blank(c));
    } else {
      return -1;
    }
#endif
    if(is_digit(c)){            /* # <line> <file> */
        unsigned num = c - '0';
        for(;;){
            c = Ref(++i);
            if(is_digit(c))
                num = num * 10 + c - '0';
            else
                break;
        }
        /* line_number'll be incremented soon */
        line_number = num - 1; 
        if(is_blank(c)){
            do{
                c = Ref(++i);
            }while(is_blank(c));
            if(c == '"'){
                size_t fname_start = i;
                do{
                    c = Ref(++i);
                } while(c != '"');
                if(i > fname_start + 2){
                    filename = fname_start;
                    filename_length = i - fname_start + 1;
                }
            }
        }
    }
    return line_number;
}

Comments