mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
fish_indent: skip past illegal byte sequences
garbage input, indented garbage output. We print a warning, and will eventually exit 1
This commit is contained in:
parent
e0d7f0bc96
commit
d080182686
1 changed files with 14 additions and 3 deletions
|
@ -47,17 +47,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|||
// An indent_t represents an abstract indent depth. 2 means we are in a doubly-nested block, etc.
|
||||
typedef unsigned int indent_t;
|
||||
static bool dump_parse_tree = false;
|
||||
static int ret = 0;
|
||||
|
||||
// Read the entire contents of a file into the specified string.
|
||||
static wcstring read_file(FILE *f) {
|
||||
wcstring result;
|
||||
while (1) {
|
||||
wint_t c = fgetwc(f);
|
||||
|
||||
if (c == WEOF) {
|
||||
if (ferror(f)) {
|
||||
if (errno == EILSEQ) {
|
||||
// Illegal byte sequence. Try to skip past it.
|
||||
clearerr(f);
|
||||
int ch = fgetc(f); // for printing the warning, and seeks forward 1 byte.
|
||||
debug(1, "%s (byte=%X)", strerror(errno), ch);
|
||||
ret = 1;
|
||||
continue;
|
||||
} else {
|
||||
wperror(L"fgetwc");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
result.push_back((wchar_t)c);
|
||||
|
@ -551,5 +562,5 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
fputws(str2wcstring(colored_output).c_str(), stdout);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue