ned14 / pcpp

A C99 preprocessor written in pure Python
Other
215 stars 39 forks source link

#include "..." parses the file name incorrectly. It is **not** a string literal. #89

Open mrolle45 opened 8 months ago

mrolle45 commented 8 months ago

The difference between a string literal in C and a quoted header name is that the latter is " q-char-sequence " in the Standard (section 6.10.2). This is indeed also a valid string literal, but not vice versa. A string literal can include an encoding prefix (such as L) and escape sequences. pcpp looks for a string literal following #include. It uses the characters in the token's value as the file name. Instead, it should look for " q-char-sequence ". Examples:

#include L"test.h"

This will try to open "test.h" but with wide characters in the string, which is not what is intended. Instead, this should be a syntax error (assuming L is not a macro).

#include "..\test.h"`

The intention is to open "test.h" in the parent directory (on Windows systems). The \ is just an ordinary character in the file name. pcpp will try to open "..\test.h" in the current directory, with ]t` being a tab character.

The fix Use similar code to that used for #include < h-char-sequence >. Note (Standard section A.1.8), an h-char is any character other than > or \n.

ned14 commented 8 months ago

Seems reasonable.