Skip to content

Commit

Permalink
Allow argc = 0.
Browse files Browse the repository at this point in the history
This is allowed according to the C++ standard, so don’t invoke undefined
behavior when converting argv[0] to a string.
  • Loading branch information
phst committed Dec 23, 2021
1 parent 780d8d8 commit 7157c29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions elisp/binary.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include "elisp/binary.h"

int PHST_RULES_ELISP_MAIN(int argc, phst_rules_elisp::NativeChar** argv) {
std::vector<phst_rules_elisp::NativeString> args = {
using phst_rules_elisp::NativeString;
using phst_rules_elisp::RunBinary;
std::vector<NativeString> args = {
[[args]],
PHST_RULES_ELISP_NATIVE_LITERAL("--")
};
args.insert(args.end(), argv, argv + argc);
return phst_rules_elisp::RunBinary(argv[0], args);
return RunBinary(argc == 0 ? NativeString() : argv[0], args);
}

// Local Variables:
Expand Down
6 changes: 4 additions & 2 deletions emacs/driver.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include "elisp/emacs.h"

int PHST_RULES_ELISP_MAIN(int argc, phst_rules_elisp::NativeChar** argv) {
std::vector<phst_rules_elisp::NativeString> args = {
using phst_rules_elisp::NativeString;
using phst_rules_elisp::RunEmacs;
std::vector<NativeString> args = {
[[args]],
PHST_RULES_ELISP_NATIVE_LITERAL("--")
};
args.insert(args.end(), argv, argv + argc);
return phst_rules_elisp::RunEmacs(argv[0], args);
return RunEmacs(argc == 0 ? NativeString() : argv[0], args);
}

// Local Variables:
Expand Down

0 comments on commit 7157c29

Please sign in to comment.