[fidl][formatter] Do not add argv[0] to sources
The fidl-format binary treats itself and program arguments as sources.
Fix this by skipping past non-file arguments.
Test: Ran "fidl-format" on a file.
Change-Id: I565fce90d692b9e94d6af8bc6804eed3010d4a27
diff --git a/system/host/fidl/formatter/main.cpp b/system/host/fidl/formatter/main.cpp
index 073963e..0877e49 100644
--- a/system/host/fidl/formatter/main.cpp
+++ b/system/host/fidl/formatter/main.cpp
@@ -63,11 +63,8 @@
} // namespace
int main(int argc, char* argv[]) {
- std::vector<std::string> args(argc);
- for (int i = 0; i < argc; i++) {
- args[i] = argv[i];
- }
-
+ // Construct the args vector from the argv array.
+ std::vector<std::string> args(argv, argv + argc);
bool in_place = false;
int pos = 1;
// Process options
@@ -91,9 +88,9 @@
fidl::SourceManager source_manager;
// Process filenames.
- for (const auto& arg : args) {
- if (!source_manager.CreateSource(arg.data())) {
- Fail("Couldn't read in source data from %s\n", arg.data());
+ for (size_t i = pos; i < args.size(); i++) {
+ if (!source_manager.CreateSource(args[i])) {
+ Fail("Couldn't read in source data from %s\n", args[i].c_str());
}
}