[libc-commits] [PATCH] D139891: [libc] fix scanf error handling
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Dec 13 12:51:41 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGddae13c30357: [libc] fix scanf error handling (authored by michaelrj).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139891/new/
https://reviews.llvm.org/D139891
Files:
libc/src/stdio/scanf_core/file_reader.h
libc/src/stdio/scanf_core/reader.cpp
libc/src/stdio/scanf_core/reader.h
libc/src/stdio/scanf_core/scanf_main.cpp
Index: libc/src/stdio/scanf_core/scanf_main.cpp
===================================================================
--- libc/src/stdio/scanf_core/scanf_main.cpp
+++ libc/src/stdio/scanf_core/scanf_main.cpp
@@ -35,7 +35,7 @@
}
}
- if (conversions == 0 && ret_val != READ_OK) {
+ if (conversions == 0 && reader->has_error()) {
// This is intended to be converted to EOF in the client call to avoid
// including stdio.h in this internal file.
return -1;
Index: libc/src/stdio/scanf_core/reader.h
===================================================================
--- libc/src/stdio/scanf_core/reader.h
+++ libc/src/stdio/scanf_core/reader.h
@@ -45,6 +45,8 @@
void ungetc(char c);
size_t chars_read() { return cur_chars_read; }
+
+ bool has_error();
};
} // namespace scanf_core
Index: libc/src/stdio/scanf_core/reader.cpp
===================================================================
--- libc/src/stdio/scanf_core/reader.cpp
+++ libc/src/stdio/scanf_core/reader.cpp
@@ -33,5 +33,12 @@
}
}
+bool Reader::has_error() {
+ if (reader_type == ReaderType::File) {
+ return file_reader->has_error();
+ }
+ return false;
+}
+
} // namespace scanf_core
} // namespace __llvm_libc
Index: libc/src/stdio/scanf_core/file_reader.h
===================================================================
--- libc/src/stdio/scanf_core/file_reader.h
+++ libc/src/stdio/scanf_core/file_reader.h
@@ -30,6 +30,7 @@
char get_char();
void unget_char(char c);
+ bool has_error() { return file->error_unlocked(); }
};
} // namespace scanf_core
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139891.482602.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221213/a212010c/attachment.bin>
More information about the libc-commits
mailing list