about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2017-12-15T00·11-0500
committerBen Gamari <ben@smart-cactus.org>2017-12-15T00·11-0500
commit626a94d70ea7a5c5b87f4d6061633c019ca8ea13 (patch)
treec8a1b94b50b0a5c4da40c80e9b34cd22fa797703 /src
parentf9bcbddef260872878708317e9f5fa78cd0fe849 (diff)
edit: Catch stoi exceptions from line number parsing
Diffstat (limited to 'src')
-rw-r--r--src/nix/edit.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/nix/edit.cc b/src/nix/edit.cc
index 127be321eee2..7eaa86e2f914 100644
--- a/src/nix/edit.cc
+++ b/src/nix/edit.cc
@@ -52,7 +52,12 @@ struct CmdEdit : InstallableCommand
             throw Error("cannot parse meta.position attribute '%s'", pos);
 
         std::string filename(pos, 0, colon);
-        int lineno = std::stoi(std::string(pos, colon + 1));
+        int lineno;
+        try {
+            lineno = std::stoi(std::string(pos, colon + 1));
+        } catch (std::invalid_argument e) {
+            throw Error("cannot parse line number '%s'", pos);
+        }
 
         auto editor = getEnv("EDITOR", "cat");